Is it possible to define "virtual" default implemetation for getter-setter without preprocessor macros <p>It is possible to use template for default implemetation of getter-setter. </p> <p>For instance - <a href="http://www.kirit.com/C%2B%2B%20killed%20the%20get%20%26%20set%20accessors/A%20simple%20meta-accessor" rel="nofollow">http://www.kirit.com/C%2B%2B%20killed%20the%20get%20%26%20set%20accessors/A%20simple%20meta-accessor</a>. Most important, that if you decide to override default behaviour of such setter or getter, you can easly do this without need to change "client" code, because setter-getter calling syntax is same to calling methods, i.e.:</p> <pre><code>an_object.an_int( 3 ); int i = an_object.an_int(); </code></pre> <p>In both cases an_int can be object with operator() or method of an_object. After overriding re-compilation will be required in "client" code.</p> <p>But is it possible to define "virtual" default implemetation for getter-setter without preprocessor macros? i.e. important thing here is that during overide recompilation of "client" code is not needed. Of course it is possible to do with preprocessor, by I wonder, is there any more elegant solution?</p> <p>For my knowladge of C++03 is not possible, but maybe someone has some ideas, or maybe it is possible in C++11?</p> <hr> <p>Answer for "David Rodríguez - dribeas": something like this:</p> <pre><code>#define accessor(type,name) \ virtual type name() {return m_##name;} \ type m_##name; </code></pre> <p>It can be overrided in derived class without need of recompilation of "client" code.</p>