姬長信(Redy)

c – friend声明声明一个非模板函数


参见英文答案 > overloading friend operator????????????????????????????????????5个
我有一个基类类似于下面的代码.我试图重载
base.h:24: warning: friend declaration ‘std::ostream& operator*)’ declares a non-template function
base.h:24: warning: (if this is not what you intended, make sure the function template has already been declared and add  after the function name here) -Wno-non-template-friend disables this warning

我试过添加在

template 
class Base {
  public:
    friend ostream& operator  *e);
};

base.cpp

ostream& operator *e) {
    out data;
return out;
}

我想在标题base.h中有这个或类似的东西:

template 
class Base {
  public:
    friend ostream& operator  *e);
};

template 
ostream& operator *e) {
    out data;
return out;
}

我在网上其他地方读到过之间

最佳答案