Const member function and typedef, C++ -
suppose want declare const member function via typedef
:
typedef int fc() const; typedef int f(); struct { fc fc; // fine, have 'int fc() const' const f fc; // not fine, 'const' ignored, have 'int fc()' };
since const
ignored program compiles fine. why const
ignored function? since can form const pointer in way thing can think of 'c heritage'. standard it?
c++ 14 standard, [dcl.fct] pt. 7:
the effect of cv-qualifier-seq in function declarator not same adding cv-qualification on top of function type. in latter case, cv-qualifiers ignored. [ note: function type has cv-qualifier-seq not cv-qualified type; there no cv-qualified function types. — end note ]
example:
typedef void f(); struct s { const f f; // ok: equivalent to: void f(); };
so, correct behavior.
Comments
Post a Comment