diamondback
10/7/2008 2:41:00 PM
On Oct 6, 11:29 pm, "A.Gallus" <u...@rz.uni-karlsruhe.de> wrote:
> Turns out I have a made a define years ago:
>
> #define play() (*this.*play)()
>
> This should be responsible for the trouble.
>
> Regards
>
> R4DIUM
>
> "news.aioe.org" <bigmur...@yahoo.com> schrieb im Newsbeitragnews:gce83m$ude$1@aioe.org...
>
> > A.Gallus wrote:
> >> in my class I have defined a functionpointer like this:
>
> >> class A
>
> >> {
>
> >> private:
>
> >> Videothing * Video;
> >> void (A::*play) (); // <== funcpointer
> >> void somefunc();
>
> >> }
>
> >> In somefunc() i do:
>
> >> this->Video->play();
>
> >> and the intel compiler outputs:
>
> >> "Error: expected a member name"
>
> >> Somehow he mixes-up the play() in the Videothing and the play
> >> functionpointer in the class A.
> >> This is the case although the functionpointer and the play() method have
> >> completely different signatures.
> >> If I rename Video->play() to Video->p() everything works fine.
>
> >> What can I do about this issue without haveing to rename my
> >> method/funcpointer?
>
> >> Regards
>
> >> R4DIUM
>
> > Are you sure the error you are seeing has anything to do with "play"?
> > I took your code and compiled with a dummy def for Videothing and an intel
> > compiler (Intel makes compilers?) compiled it just fine.
>
> > struct Videothing
> > {
> > int play(int) { return 0; }
> > };
>
> > class A
> > {
>
> > private:
>
> > Videothing * Video;
> > void (A::*play) (); // <== funcpointer
> > void somefunc()
> > {
> > this->Video->play(0);
> > }
>
> > };
>
>
This is exactly why #define macros are not recommended in C++. There
are many, much safer, ways of doing this ( Static methods, classes,
etc. ). Good catch.