这个类模版哪里有问题?VC++6.0
template<typenamet>classcomplex{protected:treal,image;public:complex(tr1=0,ti1=0){rea...
template <typename t>
class complex
{
protected:
t real, image;
public:
complex(t r1 = 0, t i1 = 0)
{
real = r1;
image = i1;
}
template <typename t>
friend ostream &operator<<(ostream &output, const complex<t> &c)
{
output<<"complex: "<<c.real<<'\t'<<c.image<<endl;
return output;
}
};
D:\我的文档\MyProject\example\10\10_08\10_08.cpp(19) : error C2562: '<<' : 'void' function returning a value
D:\我的文档\MyProject\example\10\10_08\10_08.cpp(16) : see declaration of '<<'
D:\我的文档\MyProject\example\10\10_08\10_08.cpp(26) : see reference to function template instantiation 'void __cdecl operator <<(class std::basic_ostream<char,struct std::char_traits<char> > &,const class complex<int> &)' being compiled
执行 cl.exe 时出错. 展开
class complex
{
protected:
t real, image;
public:
complex(t r1 = 0, t i1 = 0)
{
real = r1;
image = i1;
}
template <typename t>
friend ostream &operator<<(ostream &output, const complex<t> &c)
{
output<<"complex: "<<c.real<<'\t'<<c.image<<endl;
return output;
}
};
D:\我的文档\MyProject\example\10\10_08\10_08.cpp(19) : error C2562: '<<' : 'void' function returning a value
D:\我的文档\MyProject\example\10\10_08\10_08.cpp(16) : see declaration of '<<'
D:\我的文档\MyProject\example\10\10_08\10_08.cpp(26) : see reference to function template instantiation 'void __cdecl operator <<(class std::basic_ostream<char,struct std::char_traits<char> > &,const class complex<int> &)' being compiled
执行 cl.exe 时出错. 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询