使用友员出现警告的问题?
我的代码如下,因为我是想实现图的各种操作,原代码很长,所以只贴了一部分,友元函数已经定义.且没错.
但是编译器会出警告.大家看下是怎么回事?谢谢.
警告信息如下 :
[Warning] friend declaration `std::istream& operator>>(std::istream&, MatrixGraph<T, E>&)'
declares a non-template function
但是编译器会出警告.大家看下是怎么回事?谢谢.
#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
...全文


