Jump to content
  • Advertisement
Sign in to follow this  
warp X

pointers to member functions with vs .net 2003

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I tried the following code with vs .net 2003:
class Foo 
{
public: 
	double One( long inVal ); 
	double Two( long inVal ); 
};
void main() 
{
	double (Foo::*funcPtr)( long ) = &Foo::One;  
	Foo aFoo;
	double result =(aFoo.*funcPtr)( 2 );  
}





but I got this kind of compiler error: Test error LNK2019: unresolved external symbol "public: double __thiscall Foo::One(long)" (?One@Foo@@QAENJ@Z) referenced in function _main I was trying to memorize how to use these pointers. The example was from http://www.goingware.com/tips/memberpointers.html Any ideas, why it won't compile?

Share this post


Link to post
Share on other sites
Advertisement
The function Foo::One isn't defined.

double One( long inVal ){return 0.0};

Share this post


Link to post
Share on other sites
Heheh, your code is perfectly fine, that's a linker error, because you haven't defined the function. Which is A Bad Thing because you're calling it in your code [grin]

Share this post


Link to post
Share on other sites
New question:

How do I use them with pointers to objects then? If I change the code like this:


class Foo
{
public:
double One( long inVal ) {return 0.0;}
double Two( long inVal ) {return 0.0;}
};
void main()
{
double (Foo::*funcPtr)( long ) = &Foo::One;
Foo * aFoo = new Foo();
double result = aFoo->funcPtr( 2 );
}




I get this kind of error:

error C2039: 'funcPtr' : is not a member of 'Foo'

Share this post


Link to post
Share on other sites
That is right. But, I tried it:


class Foo
{
public:
double One( long inVal ) {return 0.0;}
double Two( long inVal ) {return 0.0;}
};
void main()
{
double (Foo::*funcPtr)( long ) = &Foo::One;
Foo * aFoo = new Foo();
double result = aFoo->*funcPtr( 2 );
}




and now it complains this:

error C2064: term does not evaluate to a function taking 1 arguments

What about this? It seems irrational.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!