c++ - Function pointer to a template class -


i need on strange mix between function pointers , templates...

my target :

you have class : template<typename b> class a, , instanciate b member. want acces b getter/setter.

i tried :

class b_example { public:     b_example(int v):m_var(v){}     int getvar() { return m_var; }     void setvar(int v) { m_var = v; }  private:     int m_var; };   template<typename b> class { public:     a():m_b(b(5))     {         = &m_b.getvar;         set = &m_b.setvar;     }      int (b::*get)();     void (b::*set)(int);  private:     b m_b; };   int main(int argc, char** argv) {     a<b_example> a_instance;     b_example b_instance(5);       int = (a_instance.get*)();      std::cout << << std::endl; } 

thank's help.

alexandre

first, fix syntax errors:

get = &b::getvar; set = &b::setvar; 

then, member-function pointer needs called on object. without knowing purpose of these strange pointers, can't guess want here. maybe want call on b_instance:

int = (b_instance.*a_instance.get)(); 

or maybe want call on m_b object within a_instance; can't because it's private. if that's case, want regular member functions, rather weird function pointers

int get() {return m_b.getvar();} void set(int v) {m_b.setvar(v);} 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -