error c2678解決方法

2021-07-08 11:30:41 字數 1058 閱讀 3864

使用ue4時發生

error c2678: binary 『==』 : no operator found which takes a left-hand operand of type 『const hudmessage』 (or there is no acceptable conversion)

最後可以定位到這裡

int32 find(const elementtype& item) const

}return index_none;

}

可以看到,是因為使用了tarray的find方法,但是tarray儲存的自定型別hudmessage沒有過載==運算子,所以*data == item找不到指定運算子過載。於是新增:

bool hudmessage::operator ==(const hudmessage& a)

結果還是報錯。。。

最後再次仔細閱讀錯誤資訊,發現

left-hand operand of type 『const hudmessage』

這一句提到接受的運算元是const hudmessage,於是就明白了,data在上下文中可以看到,是乙個const型別,這時候編譯器找的是左右運算元都為const的operator ==,而不是我們過載的左運算元為正常變數,右運算元為const的operator ==。所以解決方法有二:

1.過載函式加const修飾符,本質是使編譯時加入的this指標變為const,即左運算元變為const

bool hudmessage::operator ==(const hudmessage& a)const

2.直接全域性過載相應運算子

bool

operator ==(const hudmessage& a,const hudmessage& b)

但是因為標頭檔案的include順序問題方法二總是重定義,於是選擇方法一,編譯通過。

這個問題告訴我們,還是應該仔細看error。。。

VS2012 error C4996解決方法

用intel ipp庫時,函式 ippimirror 8u c1ir被通知已經過期,必須用ippimirror 8u c1r.報錯 error c4996 ippimirror 8u c1ir is deprecated.removal 2h 2014 or later.replace with i...

亂碼解決方法

jsp頁面顯示亂碼 pageencoding utf 8 servlet頁面顯示亂碼 在response輸出內容之前,執行response.setcontenttype text html charset utf 8 post表單傳遞引數亂碼 通過jsp頁面 html頁面或者servlet中的表單元...

usr bin ld lc解決方法

背景 使用海思交叉編譯器編譯庫檔案中出現。原因 ld表示連線,lc表示需要連線libc.a。出現這個,說明缺少需要的libc.a檔案。解決過程 剛開始以為是海思交叉編譯器的問題,便在安裝目錄find libc.a,找到很多個,排除這個原因 然後檢查路徑問題,發現路徑也沒問題。回想一下,虛擬機器是mi...