Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

dzl

Pointers to members

This topic is 5377 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

Why are the first adresses the same? But works well... How does the compiler implement it? Thanks to all!
#include <iostream>
using namespace std;
class myclass
{
public:
      void f(){cout<<" f() "<<endl;};
      void ff(){cout<<" ff() "<<endl;};
      int _i;
      static int _k;
};

int myclass::_k = 555;
 
int main()
{
        myclass mc;
        void (myclass::*pf)() = &myclass::f;
        void (myclass::*pff)() = &myclass::ff;
        int  myclass::*p_i = &myclass::_i;
        int  *p_k = &myclass::_k;
        (mc.*pf)();
        (mc.*pff)();
        cout <<  pf << ' '<< pff << ' ' << p_i << ' ' << p_k;
}
[edited by - dzl on March 25, 2004 7:32:07 AM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
AFAIK, you should make class members static for those functions you want to pass the pointer.

Your getting around this by using the namespace (class) qualifier. (myclass:

Look up functors instead.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!