[英]Template specialization of a member function
我必須在(C ++,我正在使用MS Visual Studio 2008 SP1)中對類成員函數使用顯式特化,但是我無法成功編譯它。 入門
錯誤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;
}
您對operator <<的顯式特化與聲明的參數列表不匹配; T const& data
vs std::ofstream& out
。 這個編譯在MSVC10中。
template<>
File& File::operator<< <std::ofstream> (const std::ofstream& out)
{
mOutPutFile << out;
return *this;
}
注意在函數參數之前添加了const
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.