const-method

    2熱度

    2回答

    class AccountManager { private: Account accountlist[100]; int *accountNumber; Account* SuperVipAccount; static int ManagerNumber; public int getManagerNumber() const; };

    0熱度

    2回答

    要定義第二個const版本的函數,是否可以安全地執行此操作?它看起來像會有無限遞歸,因爲我想返回const,但我打算調用的另一個函數是非const。 它適用於g ++,但我擔心這是不安全的。 #include <iostream> using namespace std; class test { public: int* doSomething(int a) {

    13熱度

    13回答

    我工作的一些C++代碼,我有私人的方式,如 void NotifyFooUpdated(); 它呼籲該對象的聽衆OnFooUpdated()方法幾個經理的對象。 請注意,它們不會修改此對象的狀態,因此它們在技術上可以作爲const方法,即使它們通常會整體修改系統的狀態。特別是,監聽器對象可能會回調這個對象並對其進行修改。 個人而言,我想離開他們,因爲他們不聲明它們const。但是,我們的靜態代