0
我在下面的代碼的第一個if語句的表達式中收到錯誤(標識符「isEqualTo」未定義)。在給定的代碼中獲取錯誤(標識符未定義)
'template <typename T>
T isEqualTo<bool>(T arg1, T arg2)
{
if (arg1 == arg2)
return true;
else
return false;
}
int main()
{
int i1 = 1, i2 = -1, i3 = 2, i4 = 4;
cout << "*** Integers Tests ***\n";
if (isEqualTo(i1, i1))
cout << "Integers: " << i1 << " and " << i1 << " are equal\n";
else
cout << "Integers: " << i1 << " and " << i1 << " are \"Not\" equal\n";
if (isEqualTo(i3, i4))
cout << "Integers: " << i3 << " and " << i4 << " are equal\n";
else
cout << "Integers: " << i3 << " and " << i4 << " are \"Not\" equal\n";'
有人能告訴我我做錯了什麼,我該如何解決?
是否有可能我得到這個錯誤,因爲,因爲當我刪除它時,這個錯誤消失了。但是,如果表達式在我的用戶定義類型中出現新錯誤。 –
是的。這裏不應該包含''。編譯器將實例化它並根據實際參數的類型確定T. –
gdlmx
當我不包含它時,我在我的if語句中得到錯誤(表達式必須有bool類型),其中我的參數是用戶定義的類的對象。 –