Calling a object's overloaded operator with a pointer to that object.

Discussion in 'C++' started by matt p, Nov 7, 2004.

  1. matt p

    matt p Guest

    example:
    FunClass myfun;
    FunClass *lotsofunptr=&myfun;

    myfun[string]; //calls the overloaded [] operator;


    lotsofunptr->[string];//error

    help is much apreciated
     
    matt p, Nov 7, 2004
    #1
    1. Advertising

  2. Re: Calling a object's overloaded operator with a pointer to thatobject.

    matt p wrote:
    > example:
    > FunClass myfun;
    > FunClass *lotsofunptr=&myfun;
    >
    > myfun[string]; //calls the overloaded [] operator;


    How does your signature of the overloaded function look like ?
    And what is 'string' . C++ std. specifies it to be a type in std
    namespace.

    >
    >
    > lotsofunptr->[string];//error
    >


    Post compilable code here to seek help.

    --
    Karthik. http://akktech.blogspot.com .
    'Remove _nospamplz from my email to mail me.'
     
    Karthik Kumar, Nov 7, 2004
    #2
    1. Advertising

  3. Re: Calling a object's overloaded operator with a pointer to thatobject.

    Karthik Kumar wrote:
    > matt p wrote:
    >
    >> example:
    >> FunClass myfun; FunClass *lotsofunptr=&myfun;
    >>
    >> myfun[string]; //calls the overloaded [] operator;


    Assuming string to be a variable, (a bad choice for naming it
    though) and of the same type as the overloaded function would expect ,
    here it goes.

    myfun[string] ;

    is essentially

    myfun.operator[](string)



    >
    >
    > How does your signature of the overloaded function look like ?
    > And what is 'string' . C++ std. specifies it to be a type in std
    > namespace.
    >
    >>
    >>
    >> lotsofunptr->[string];//error


    So if you want to get the same thing as that of a pointer , use

    (*lotsofunptr)[string];

    You essentially dereference the pointer and apply the same syntax.
    If you are not happy then use

    lotofunptr->operator[](string)

    That should work fine too.


    >>

    >
    > Post compilable code here to seek help.
    >



    --
    Karthik. http://akktech.blogspot.com .
    'Remove _nospamplz from my email to mail me.'
     
    Karthik Kumar, Nov 7, 2004
    #3
  4. matt p wrote:

    > example:
    > FunClass myfun;
    > FunClass *lotsofunptr=&myfun;
    >
    > myfun[string]; //calls the overloaded [] operator;
    >
    >
    > lotsofunptr->[string];//error


    (* lotsofunptr) [string];

    lotsofunptr->operator [] (string);

    --
    Salu2
     
    =?ISO-8859-15?Q?Juli=E1n?= Albo, Nov 7, 2004
    #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. glen stark
    Replies:
    3
    Views:
    533
    glen stark
    Sep 30, 2003
  2. John Goche
    Replies:
    2
    Views:
    348
    Frederick Gotham
    Sep 4, 2006
  3. Afshin
    Replies:
    0
    Views:
    294
    Afshin
    Aug 12, 2011
  4. Afshin
    Replies:
    0
    Views:
    300
    Afshin
    Aug 12, 2011
  5. Afshin
    Replies:
    7
    Views:
    440
    Victor Bazarov
    Aug 16, 2011
Loading...

Share This Page