pointer to non-static member function

This topic is 4885 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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)

Share on other sites
Interesting.

Generally, you implement typedef.

Kuphryn

Share on other sites
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

Share on other sites
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.

Share on other sites
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

Share on other sites
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

Share on other sites
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]

Share on other sites
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

Share on other sites
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

Share on other sites
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...};

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 9
• 34
• 16
• 11
• Forum Statistics

• Total Topics
634123
• Total Posts
3015651
×