[英]Template specialization of a member function
I have to use an explicit specialization for a class member function in (C++ , I am using MS Visual Studio 2008 SP1), but I could not success to compile it. 我必须在(C ++,我正在使用MS Visual Studio 2008 SP1)中对类成员函数使用显式特化,但是我无法成功编译它。 Getting
入门
error C2910: 'File::operator <<' : cannot be explicitly specialized
错误C2910:'File :: operator <<':无法显式专门化
class File
{
std::ofstream mOutPutFile;
public:
template<typename T>
File& operator<<(T const& data);
};
template<typename T>
File& File::operator<< (T const& data)
{
mOutPutFile << preprosesor(data);
return *this;
}
template< >
File& File::operator<< <> (std::ofstream& out)
{
mOutPutFile << out;
return *this;
}
Your explicit specialization of operator << didn't match the parameter list of the declaration; 您对operator <<的显式特化与声明的参数列表不匹配;
T const& data
vs std::ofstream& out
. T const& data
vs std::ofstream& out
。 This one compiles in MSVC10. 这个编译在MSVC10中。
template<>
File& File::operator<< <std::ofstream> (const std::ofstream& out)
{
mOutPutFile << out;
return *this;
}
Notice const
added before the function parameter. 注意在函数参数之前添加了
const
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.