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 );
}
pointers to member functions with vs .net 2003
I tried the following code with vs .net 2003:
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?
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]
New question:
How do I use them with pointers to objects then? If I change the code like this:
I get this kind of error:
error C2039: 'funcPtr' : is not a member of 'Foo'
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'
That is right. But, I tried it:
and now it complains this:
error C2064: term does not evaluate to a function taking 1 arguments
What about this? It seems irrational.
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.
double result =aFoo->*funcPtr( 2 );// todouble result =(aFoo->*funcPtr)( 2 );
That should work.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement