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

Discussion in 'C++' started by viki, Apr 15, 2008.

  1. viki

    viki Guest

    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.
    viki, Apr 15, 2008
    #1
    1. Advertising

  2. viki

    Krice Guest

    On 15 huhti, 09:15, viki <> wrote:
    > We do not want to use macro, we want the C++ equivalent.


    You are greys aren't you? You guys just don't get how
    obviously you are space aliens:)
    Krice, Apr 15, 2008
    #2
    1. Advertising

  3. viki

    Ian Collins Guest

    viki wrote:
    > 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.

    --
    Ian Collins.
    Ian Collins, Apr 15, 2008
    #3
  4. viki

    Ian Collins Guest

    Alf P. Steinbach wrote:
    >
    > 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!

    --
    Ian Collins.
    Ian Collins, Apr 15, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. 0to60
    Replies:
    4
    Views:
    515
    jeffc
    Nov 21, 2003
  2. Grey Squirrel

    Hungarian Notation Vs. Pascal Notation?

    Grey Squirrel, Mar 19, 2007, in forum: ASP .Net
    Replies:
    6
    Views:
    1,300
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
    Mar 21, 2007
  3. Tameem
    Replies:
    454
    Views:
    11,846
  4. Robert Mark Bram

    Dot notation V Bracket notation

    Robert Mark Bram, Jul 4, 2003, in forum: Javascript
    Replies:
    3
    Views:
    467
    Robert Mark Bram
    Jul 5, 2003
  5. Ste
    Replies:
    41
    Views:
    808
    Thomas 'PointedEars' Lahn
    Aug 1, 2007
Loading...

Share This Page