小编Pet*_*ich的帖子

C++中的朋友和模板

我的C++代码示例中存在一个大问题."朋友"和"模板"有问题.

错误消息:
Matrix.h:26:79:警告:

friend声明'std :: ostream&matrixClass :: operator <<(std :: ostream&,const matrixClass :: Matrix&)'声明一个非模板函数[-Wnon-template-friend] friend std :: ostream&operator <<(std :: ostream&,const Matrix&matrix);

Matrix.h:26:79:注意:

  (if this is not what you intended, make sure the function template
Run Code Online (Sandbox Code Playgroud)

已声明并在此处添加<>后的函数名称)

Matrix.h:28:77:警告:

  friend declaration 'matrixClass::Matrix<T>*
Run Code Online (Sandbox Code Playgroud)

matrixClass :: operator*(const matrixClass :: Matrix&,const matrixClass :: Matrix&)'声明一个非模板函数[-Wnon-template-friend]朋友Matrix*operator*(const Matrix&m1,const Matrix&m2);

Matrix.cpp:1:0:

C:\ Users\Peter\CLIONProjects\PK\untitled76\Matrix.h:26:79:警告:朋友声明'std :: ostream&matrixClass :: operator <<(std :: ostream&,const matrixClass :: Matrix&)'声明非模板函数[-Wnon-template-friend]朋友std :: ostream&operator <<(std :: ostream&,const Matrix&matrix);

Matrix.h:26:79:注意:

  (if this is not what you intended, make sure …
Run Code Online (Sandbox Code Playgroud)

c++ templates friend shadow operator-keyword

6
推荐指数
1
解决办法
438
查看次数

标签 统计

c++ ×1

friend ×1

operator-keyword ×1

shadow ×1

templates ×1