hiding function call under the "instance->member" notation

V

viki

We have zillion of instances inf instance->m_member in the code.
We are going introduce the 'accessors' Get() and Set() for m_member,
and
m_member going private (and renamed, too). We would like to leave, if
possible,
refs inst->m_member in the code, but make compiler translate
it to inst->Get() invisily, and without using macros. Let's assume T
is
a type of m_member.

Is there any c++ trick to redirect inst->m_foo /* no parentheses
after m_foo */
to function call inst->Get(), without using macros ? I am sure there
is some
trick of declaring m_foo a special small class that evaluates a
function
when accessed, but I can't figure it out.

Apparently semi-possible with #define (only outside of the class):
#define m_member Get()
but that sucks
(you do not need to enumerate all reasons why it sucks, we are not
going to use it; this just to illustrates equivalent of what we
want).
We do not want to use macro, we want the C++ equivalent.

V.M.
 
I

Ian Collins

viki said:
We have zillion of instances inf instance->m_member in the code.
We are going introduce the 'accessors' Get() and Set() for m_member,

Why?

Ge/set accessors are invariably a design smell. Unless they do
something other than just getting and setting the value, they are a smell.
 
I

Ian Collins

Alf said:
Cheers, & hope you tackle the design rather than doing silly things like
above,
That was a bit like teaching someone how to ride a bike naked down a
black run!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top