pointer to non-static member function

Started by
8 comments, last by nmi 18 years, 7 months ago
Well i've all but given up on this, im at a loss as to whats wrong, basically all i can do is give you my source and my error, im at a total loss viewport.h

class viewport
{
//.
//.
//.
public:
	SPvoid	(viewport::*TransformVertices)(SPspritevertex * vertices);
};


sprite.cpp

SPvoid		sprite::Build(SPspritevertex * vertices)
{
	(this->*BuildVertices)(vertices);
	(this->*BuildTexCoords)(vertices);
        ((CurrentContext->CurrentState()->Viewport).*(TransformVertices))(vertices); //error points to this line
}


c:\Documents and Settings\Dan\My Documents\Visual Studio Projects\Developer Sprite Library\sprite.cpp(41) : error C2065: 'TransformVertices' : undeclared identifier Viewport is of type viewport any insight? ive tried just about every variation on parenthesis i can think of, all have the same error thanks -Dan (note: BuildVertices and BuildTexCoords are also pointer to (non static) member functions, but they belong to the sprite class, obviously)
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
Advertisement
Interesting.

Generally, you implement typedef.

Kuphryn
Nope :-/ i really appreciate the help though. Ive been wondering for a while if my problem might stem from some circular file inclusions or something

thanks a lot
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
I assume, since you viewport is using sprite, and sprite is using viewport, that you've forward declared the classes in the other class' headers.

So, from this, I also assume 'Viewport' in 'CurrentContext->CurrentState()' is a pointer. You'd need to access it's function pointer the same way as you've done the for the ones in the sprite class.

Also, you'll need to make sure viewport is included in your sprite.cpp, so it's not an incomplete type.
Viewport is actually not a pointer in this case, its an actual instance of the class viewport. Just for the record, i think this is a scope problem now, i wrapped up TransformVertices' call inside a public member function of viewport called TV, and when i call TV from the sprite::Build() function, it all compiles fine and dandy. I guess somehow the syntax gets perverted once you start trying to call function pointers from outside of the parent class (or perhaps its only a problem when you're within another class, i dont know)

(or finally maybe its msvc's fault, who knows) thanks for the help, I dont know what the problem is but ive got a better idea, AND i've got a workaround, however undesirable

EDIT: way to close your bold tag dan...

cheers/thanks
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
Hrm, spits out this error:

c:\Documents and Settings\Dan\My Documents\Visual Studio Projects\Developer Sprite Library\sprite.cpp(42) : error C2597: illegal reference to non-static member 'viewport::TransformVertices'
c:\Documents and Settings\Dan\My Documents\Visual Studio Projects\Developer Sprite Library\sprite.cpp(42) : error C2568: '.*' : unable to resolve function overload
unable to recover from previous error(s); stopping compilation

I wonder if its choking on the fact that it interprets the classname::classmember as accessing a static member because its outside of the class' definition

EDIT: looks silly to have my post here with the post its responding to cut out... oh well haha

thanks as well
cheers
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
viewport* Viewport = &(CurrentContext->CurrentState()->Viewport);Viewport->*(Viewport->TransformVertices))(vertices);


viewport provides the this pointer
viewport.TransformVertices provides the member function pointer

Does this work ?

[Edited by - nmi on September 7, 2005 3:56:06 AM]
It works like this:

	viewport Viewport = CurrentContext->CurrentState()->Viewport;	((Viewport).*(Viewport.TransformVertices))(vertices);


(essentially what you had with a few parenthesis and the classname and the type switched :-)

very interesting, the syntax appears to be the same doesnt it? the only difference is the trouble gone through to access it... thanks a ton

cheers
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
come to think of it thats strange in itself isnt it? i never defined an assignment operator for viewport... i suppose its being interpreted as a struct for whatever reason, (stares the problem in the face, could i have done a forward declaration as a struct and then the definition as a class and for whatever reason it didnt catch it as a redefinition?)

EDIT: unfortunately its not that simple, that wasnt the case

cheers
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
If you do not provide or declare an assignment operator/copy constructor, the compiler will create one for you that does a byte-wise copy. If you had pointers to data, then this will result in a shallow copy. If you delete that memory in the destructor, then the data is gone after sprite::Build() was called.
Thats why I took the address of the viewport, without making a copy.

You can also use a reference:
viewport& Viewport = (CurrentContext->CurrentState()->Viewport);Viewport.*(Viewport.TransformVertices))(vertices);


Just make sure that you don't make a copy, i.e. by declaring the assignement operator and copy constructor private (or define them properly):
class viewport {private:viewport(const viewport& other);  // copy constructorviewport& operator= (const viewport& other);  // assignment operator...};

This topic is closed to new replies.

Advertisement