I guess the functionality he wants is like the property keyword in VC++. Unfortunately this is a Microsoft only extension.
This is acutally stolen by Microsoft from Borland Delphi's Object Pascal.
I really liked the feature and wished C++ had a solution. I haven't spent any time thinking about adding it, or how to.
Any ideas? Suggestions?
Thanks
Boost.Test library contain header class property that implement AFAICT the solution to your problem: Example usage like this: Example1: class A{ public: A( std::string name ) : p_name( name ) {} readonly_propertystd::string p_name; }; ... A a; std::cout << a.p_name; or std::string s( a.p_name ); a.p_name = "abc"; <-- this will produce error a.p_name.value = "abc"; <-- this will produce error Example2: class A{ public: readwrite_property<int> p_id; }; ... A a; std::cout << a.p_id; a.p_id.value = 1; Example3: class A { public: BOOST_READONLY_PROPERTY( float, (B)(C) ) p_highwatermark; }; This is an example of readonly property that only accessible for modification to the methods of classes B and C HTH, Header is here: boost/test/detail/class_properties.hpp (Old version is here: http://www.boost.org/boost/test/detail/class_properties.hpp, but I recommend to use new from cvs or one that will come with next release) Gennadiy