Hello)
I have such a problem, there is a static (static) function, the pointer to which goes to another class and is called (callback). This function comes in pictures in the form of a structure with 3 char * and when I call this function, this The image must be put in the list.
But from this function I cannot call the list functions, such as push_back (), etc.
Visual Studio says see picture. alt text Thank you in advance

Code:

".h" public: static void func (BMPImage* frame); std::list <BMPImage*> images; 

".cpp"

 void Gallery::func(BMPImage* frame){ //вот тут не "видит" } 
  • Is the header connected to a cpp file? - KoVadim
  • yes of course - whispeer
  • yes (but I can’t make the list static - whispeer
  • 2
    Either make the field static, or remove the static from the method, or you must pass an instance of the class to this method. - falstaf
  • one
    Why do you need a static callback? There are method pointers. Here, [example] [1] has thrown. In general, interfaces are great for callbacks. Why not use them instead of function / method pointers? [1]: ideone.com/GCvt1U - falstaf

2 answers 2

@falstaf , do not reinvent the wheel. {boost,std}::bind(&ClassName::MethodName, this) and all.

    Your func is a static function in the Gallery class, and images is a member of the class. Static functions by their definition do not have access to class members, since * are performed in isolation from a specific object instance. *

    In C ++ 03, you can use boost::function. Actually, std::function is the same boost::function, but migrated to Standard Library.