使用友员出现警告的问题?

HNLGDXYJS 2008-11-21 04:43:04
我的代码如下,因为我是想实现图的各种操作,原代码很长,所以只贴了一部分,友元函数已经定义.且没错.
但是编译器会出警告.大家看下是怎么回事?谢谢.

#include<iostream>
using namespace std;

template<typename T,typename E>
class MatrixGraph
{
T *VerticesList; //vertex table
E **Edge; //Adjacent matrix
friend istream& operator >>(istream& in,MatrixGraph<T,E>& G);
friend ostream& operator <<(ostream& out,MatrixGraph<T,E>& G);
public:
MatrixGraph(int sz=defaultVertices);
~MatrixGraph()
{
delete [] VerticesList;
delete [] Edge;
}
};


template<typename T,typename E>
MatrixGraph<T,E>::MatrixGraph(int sz)
{
maxVertices = sz;
numVertices = numEdges = 0;
VerticesList = new T[maxVertices]; //create array of vertex table
Edge = new int *[maxVertices]; //create array of AdjacentMatrix
for (int i=0;i<maxVertices;i++)
Edge[i] = new int[maxVertices];
for (int i=0;i<maxVertices;i++)
for (int j=0;j<maxVertices;j++)
Edge[i][j] = (i==j) ? 0 : maxWeight;
}

int main(void)
{
//MatrixGraph<int,int> AdjMatG(10);
return 0;
}



警告信息如下 :

[Warning] friend declaration `std::istream& operator>>(std::istream&, MatrixGraph<T, E>&)'
declares a non-template function
...全文
94 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
HNLGDXYJS 2008-11-21
  • 打赏
  • 举报
回复
谢谢两位,已解决.
帅得不敢出门 2008-11-21
  • 打赏
  • 举报
回复
up下.
Non_Recursive 2008-11-21
  • 打赏
  • 举报
回复
提前声明模板函数,或者在类中定义友元试一下..

64,676

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧