Dev 中程式設計出現的乙個小錯誤 記住就好

2022-07-01 03:33:11 字數 942 閱讀 3608

c++ stl編譯報錯:error: error passing 'const' as 'this' argument

用c++ stl(標準模板庫)編寫仿函式的時候,編譯報錯:

error: passing 'const findnameoraddress' as 'this' argument of 'bool findnameoraddress::operator()(std::string, std::string)' discards qualifiers [-fpermissive]

其中:findnameoraddress 為類名。在使用stl中的某些演算法的時,有時候出於需要,不得不自己去實現函式物件,然後再用介面卡來繫結並匹配函式引數問題。

1

//函式介面卡 bind1st bind2nd ,二元函式物件需要繼承binary_function《引數型別,引數型別,返回值型別》;2//

若為一元函式物件,則需繼承unary_function

3struct findnameoraddress : public std::binary_functionstring,std::string, bool>

410 };

上面的類編譯就會報錯,因為我們在進行括號"()"過載時候,應該將其宣告為「

const

屬性。正確的形式如下:

1

//函式介面卡 bind1st bind2nd ,二元函式物件需要繼承binary_function《引數型別,引數型別,返回值型別》;2//

若為一元函式物件,則需繼承unary_function

3struct findnameoraddress : public std::binary_functionstring,std::string, bool>

49 };

綜上所述:加個const就好

ok

egit的乙個小錯誤

用egit和堅果雲搭配開發環境,配置egit時提示乙個錯誤 the current branch is not configured for pull.no value for key branch.master.merge found in configuration google一番後發現原來是...

ntp的乙個小錯誤

root localhost ntpdate 10.128.14.25 3 apr 21 05 05 ntpdate 1506 the ntp socket is in use,exiting 收到此錯誤訊息的原因是由於 xntpd 已經繫結到了該 socket。執行 ntpdate 時,它會首先進...

vsftp下的乙個小錯誤

之前在自己這裡試的好好的,到了機房總出這個錯誤 500 illegal port command.425 use port or pasv first.在網上找了好久都不得行,後來才知道,這樣做即可 ftp時顯示500 illegal port command的解決或者ie無法訪問解決ftp 我一直...