protected:DWORD m_dwMountTime;public: DWORD GetLastHorseTime() const return m_dwHorseTime; DWORD CHARACTER::GetMyHorseVnum() const int delta = 0; m_dwMountTime = get_dword_time(); return c_aHorseStat.iNPCRace + delta; ok, over there is my code.

You are watching: Assignment of member in read-only object

After as soon as i try to translate into i acquire an error :

char_horse.cpp: In member role "virtual DWORD CHARACTER::GetMyHorseVnum() const": char_horse.cpp:210:16: error: assignment that member "CHARACTER::m_dwHorseTime" in read-only thing m_dwHorseTime = get_dword_time();Where is the problem? :)


A member function significant const cannot readjust the state of the class. In GetMyHorseVnum() you have

m_dwMountTime = get_dword_time();Which transforms the state that the class. You either need to remove the const modifer top top the function or make m_dwMountTime mutable



You can"t change a member variable in a const member function, i beg your pardon promise won"t readjust the state of the class.

You could want to do m_dwMountTime mutable to make it modifiable:

mutable DWORD m_dwMountTime; mutable - applies to non-static course members of non-reference non-const kind and mentions that the member go not impact the externally clearly shows state that the class (as frequently used because that mutexes, memo caches, lazy evaluation, and access instrumentation). Mutable members that const classes are modifiable. (Note: the C++ language grammar treats mutable as a storage-class-specifier, yet it go not impact storage class.)


Thanks for contributing an answer to ridge Overflow!

Please be sure to answer the question. Administer details and also share your research!

But avoid

Asking for help, clarification, or responding to various other answers.Making statements based upon opinion; earlier them up with references or personal experience.

See more: What Does The Frog And Coffee Emoji Mean, What Does A Frog Mean In A Text

To discover more, see our tips on writing good answers.

post Your answer Discard

By clicking “Post your Answer”, friend agree to our terms of service, privacy policy and cookie policy

instead of a 32-bit loop counter with 64-bit introduces crazy power deviations v _mm_popcnt_u64 ~ above Intel CPUs

site style / logo design © 2021 stack Exchange Inc; user contributions license is granted under cc by-sa. Rev2021.11.10.40715

your privacy

By click “Accept every cookies”, girlfriend agree stack Exchange have the right to store cookies on your maker and disclose info in accordance with our Cookie Policy.