2
我有一個模板類template <typename T> class MyClass
與方法:C++錯誤:沒有匹配函數調用[類] :: [功能]'
void add (T& item) {
data[indexToInsert++] = &item; // data is an array of T*
}
在主:
MyClass<int> thing;
thing.add(10);
在第二行,我得到這個錯誤:
no matching function for call to MyClass::add(int)
爲什麼會發生這種情況?
像'T&'這樣的非常量左值引用不能像'10'那樣綁定到右值。無論如何,編譯器應該如何使用'10'的地址? – 2014-10-05 10:20:33