簡體   English   中英

我試圖在 C++ 中使用運算符重載,但是當我去實現該函數時,它提供了這個錯誤

[英]I am trying to use operator overloading in c++ but when I go to implement the function, it provides this error

我的函數原型是這樣的: const String operator+(const String&) const;

當我去實現這個函數時,我有這個: String String::operator+(const String&) {

}

這提供了一個錯誤,它顯示在我的 IDE 中修復它的唯一方法是更改​​我不能做的原型,這是在我的作業中給出的。 任何幫助表示贊賞。

原型的返回值是 const String 而實現中的返回值是 String (即沒有 const 限定符)。 一般來說,您應該提供更多代碼的詳細信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM