Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help: How could I deal with this?

Help: How could I deal with this?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GavinWang
    wrote on last edited by
    #1

    as follows, what should I do? thanks:) class A { public: void f(void (*g)(int), int i) const { (*g)(i); } protected: //must be virtual, some one inherit from it virtual void g(int i) const { ; } }; class B { public: B() { pa = new A; } ~B() { delete pa; } //my problem is here: the first argument pa->g :( void fb() const { pa->f( (pa->g), 0); } private: A* pa; };

    T P 2 Replies Last reply
    0
    • G GavinWang

      as follows, what should I do? thanks:) class A { public: void f(void (*g)(int), int i) const { (*g)(i); } protected: //must be virtual, some one inherit from it virtual void g(int i) const { ; } }; class B { public: B() { pa = new A; } ~B() { delete pa; } //my problem is here: the first argument pa->g :( void fb() const { pa->f( (pa->g), 0); } private: A* pa; };

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      in the destructor, before delete pa, check if it has been allocated ( != NULL). next, for your request, (pa->g) is effectively the address of your function... if there is a problem, what does the error say ?


      TOXCCT >>> GEII power

      1 Reply Last reply
      0
      • G GavinWang

        as follows, what should I do? thanks:) class A { public: void f(void (*g)(int), int i) const { (*g)(i); } protected: //must be virtual, some one inherit from it virtual void g(int i) const { ; } }; class B { public: B() { pa = new A; } ~B() { delete pa; } //my problem is here: the first argument pa->g :( void fb() const { pa->f( (pa->g), 0); } private: A* pa; };

        P Offline
        P Offline
        Prakash Nadar
        wrote on last edited by
        #3

        i dont think its possible to create a pointer to the member function and use it.


        I'll write a suicide note on a hundred dollar bill - Dire Straits

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups