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

HNLGDXYJS HNLGDXYJS 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我的代码如下,因为我是想实现图的各种操作,原代码很长,所以只贴了一部分,友元函数已经定义.且没错.
但是编译器会出警告.大家看下是怎么回事?谢谢.

#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
...全文
评论 4
收藏 已收藏
分享
返回顶部
HNLGDXYJS
C++ 语言 65,214 成员 250,514 内容