我正在使用C++,並且有一個錯誤,我不知道確切的原因。我找到了解決方案,但仍然想知道爲什麼。關於C++轉換:從'[some_class]'到'[some_class]'沒有已知的參數1轉換&'
class Base
{
public:
void something(Base& b){}
};
int main()
{
Base b;
b.something(Base());
return 0;
}
當我編譯的代碼,我得到了這個以下錯誤:
abc.cpp:12:20: error: no matching function for call to ‘Base::something(Base)’
abc.cpp:12:20: note: candidate is:
abc.cpp:6:7: note: void Base::something(Base&)
abc.cpp:6:7: note: no known conversion for argument 1 from ‘Base’ to ‘Base&’
但是當我更換b.something(基地())到
Base c;
b.something(c);
的錯誤消失,我想知道爲什麼?他們是不是有相同的類型?它只是重要的我如何寫它,但意義應該是相同的?
謝謝!
似乎是一個有效且有用的問題 - upvoted反對無法解釋的downvote。 – CompuChip
@CompuChip人喜歡你讓這個社區變得更好。 – imoutidi