As an example, I will use the following (trivial) interface:
struct IObject { virtual ~IObject() {} virtual std::string GetName() const = 0; virtual void ChangeState() = 0; };
Logic dictates what GetNameshould be a member function const, and ChangeStatenot should.
GetName
const
ChangeState
All the code I've seen so far does not follow this logic. That is, GetNamethe above example will not be marked as a member function const.
Is this laziness or negligence or is there a legitimate reason for this? What are the main flaws of me that force my clients to implement member functions constwhen they are logically called?
EDIT: Thanks for your answers. I think this is pretty much unanimous: laziness / ignorance is the reason that I see.
, /. GetName() , IObject .
GetName()
IObject
- GetName() (!) , mutable.
mutable
?
. - , , .
, - const, ?
. ( , , . , , .)
, , , , , const, , const - . , const , .const - , , const, . - ... , , const ., , - , const. , , , , .
Source: https://habr.com/ru/post/1746229/More articles:Manual data binding update in WPF MVVM - mvvmHow do you correctly catch a MySQLIntegrityConstraintViolationException? - javaInclude a repeating HTML snippet - phpIs it possible to cache the asp page on the server side? - cachingjQuery ajax multiline "script" answer - jquerySimple Java-XML Example - javanhibernate/fluenthibernate ะฒัะฑัะฐััะฒะฐะตั StackOverflowException - stack-overflowhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1746232/listening-to-php-function-calls-to-intercept-the-returned-value&usg=ALkJrhjkujdaR_-i3lwwOJpHFG0amljBUASSIS - connection management inside the loop - optimizationFind which MFC child window will get the mouse click - winapiAll Articles