Topic: Q: Calling operator() via pointer to object?


Author: Cristian Georgescu <Cristian.Georgescu@worldnet.att.net>
Date: 1998/03/18
Raw View

If I have a class with the operator() defined then for an object "obj"
of this class I can call: obj(). However if I want to make the same call
via a pointer to the object pobj I am stuck with this ugly syntax:
pobj->operator()().

Is there a better way???

     class A {
     public: int attr;
             virtual ~A(){};
             int operator()(){return 0;};
     };


     ///////////////////////////////////////////////////////////////////////////////

     void main()
     {
         A* pa;
         pa->operator()(); //???
     }

[ Moderator's note: html attachment deleted. Please do not post
  html to this newsgroup. -sdc ]


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Frederic LACHASSE <frederic.lachasse@dial.oleane.com>
Date: 1998/03/22
Raw View
Cristian Georgescu <Cristian.Georgescu@worldnet.att.net> wrote:
> If I have a class with the operator() defined then for an object "obj"
> of this class I can call: obj(). However if I want to make the same call
> via a pointer to the object pobj I am stuck with this ugly syntax:
> pobj->operator()().
>
> Is there a better way???
>

 (*pobj)();

(nothing like plain simple solutions)

 Frederic LACHASSE (ECP 86)
 Internet mailto:frederic.lachasse@dial.oleane.com
 CompuServe: 100530,2005
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]