1
我有同樣的頭文件中的兩個模板類A和B如下:模板類提供了模糊誤差
template <typename T>
class FirstClass {
public:
bool convert(const FirstClass<T>& f){...}
bool convert(const SecondClass<T>& s){...}
};
template <typename T>
class SecondClass {
public:
bool convert(const FirstClass<T>& f){...}
bool convert(const SecondClass<T>& s){...}
};
爲了解決任何未知的類錯誤,我嘗試添加一個向前聲明:
template <typename T> class SecondClass ; //adding this to the beginning of the file
我得到以下錯誤:
2 overloads have similar conversions
could be 'bool FirstClass<T>::convert(const FirstClass<T>&)'
or
could be 'bool FirstClass<T>::convert(const SecondClass<T>&)'
while trying to match the argument list '(FirstClass<T>)'
note: qualification adjustment (const/volatile) may be causing the ambiguity
我假定這是因爲我我正在使用一個前向聲明的類。除了將實現移動到Cpp文件(我被告知這很麻煩)之外,還有其他有效的解決方案嗎?
我使用的VisualStudio 2010在Windows 7上
是什麼錯誤被提高了代碼的行輸出? – Steve
爲什麼你需要從'FirstClass'轉換成'FirstClass '? –
我想這不是整個代碼,至少沒有調用'convert()'會觸發這樣的模糊性錯誤。請嘗試給我們一個最小的代碼示例,當我們編譯它時,會給出完全相同的錯誤。沒有那個代碼,人們需要一個水晶球來看看問題是什麼,而我現在已經被打破了一段時間...... –