[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

strange functionpointer / method confusion

Axel Gallus

10/6/2008 10:11:00 PM

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


4 Answers

news.aioe.org

10/6/2008 11:48:00 PM

0

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);
}

};

Axel Gallus

10/7/2008 6:30:00 AM

0

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" <bigmurali@yahoo.com> schrieb im Newsbeitrag
news: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);
> }
>
> };

Ali Karaali

10/7/2008 8:52:00 AM

0

On 7 Ekim, 01:11, "A.Gallus" <u...@rz.uni-karlsruhe.de> 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

You have defined a function pointer

void (A::*play)();

but you've not use that.

class Vide0
{
public :

void play()
{
atd::cout << "play()" << std::endl;
}
};

class A
{
Video * video;
typedef void (Video::*fPtr)();

public :

void someFunc()
{
fPtr fPlay= &Video::play;
(this->video->*fPlay)();
}
};


int main()
{
A a;

a.someFunc();
}

diamondback

10/7/2008 2:41:00 PM

0

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.