Error Reference To Non-static Member Function Must Be Called
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more reference to non-static member function must be called c++ about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users reference to non-static member function must be called sort Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping reference to non-static member function must be called xcode each other. Join them; it only takes a minute: Sign up Reference to non-static member function must be called up vote 9 down vote favorite 3 I'm using C++ (not C++11). I need to make a pointer to
Reference To Non-static Member Function Must Be Called Thread
a function inside a class. I try to do following: void MyClass::buttonClickedEvent( int buttonId ) { // I need to have an access to all members of MyClass's class } void MyClass::setEvent() { void ( *func ) ( int ); func = buttonClickedEvent; // <-- Reference to non static member function must be called } setEvent(); But there's an error: "Reference to non static member function must be called". What should I do to make a pointer non static member function without an object argument to a member of MyClass? c++ pointers reference share|improve this question edited Oct 13 '14 at 1:35 imreal 7,54621736 asked Oct 13 '14 at 1:04 JavaRunner 58421226 1 You can't have a function pointer assigned to a member function. You either have to use a pointer to member, or a free function. –imreal Oct 13 '14 at 1:16 What do you mean by the "pointer to a member"? As for "free function" you meant a function outside a class? Yeah, I know that it will work if I'll remove "MyClass::" part from definition "void MyClass::buttonClickedEvent..." but I need to have an access to members of MyClass inside the function "buttonClickedEvent"... –JavaRunner Oct 13 '14 at 1:26 add a comment| 2 Answers 2 active oldest votes up vote 9 down vote accepted The problem is that buttonClickedEvent is a member function and you need a pointer to member in order to invoke it. Try this: void (MyClass::*func)(int); func = &MyClass::buttonClickedEvent; And then when you invoke it, you need an object of type MyClass to do so, for example this: (this->*func)(
sure is causing this error because once I
Reference To Non-static Member Function Must Be Called C++11
don't comment them out pretty much everywhere Flink or Rlink is used or defined I get http://stackoverflow.com/questions/26331628/reference-to-non-static-member-function-must-be-called this error. Any ideas as to why? 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef nodes_Nodes_h #define nodes_Nodes_h #include
library Strings library Containers library Algorithms library Iterators library Numerics library Input/output library Localizations library Regular expressions library (C++11) Atomic operations library (C++11) http://en.cppreference.com/w/cpp/language/member_functions Thread support library (C++11) Filesystem library (C++17) Technical Specifications [edit] C++ language Classes General overview class/struct types union types Members data members static members the this pointer nested classes member templates bit fields using-declarations member functions member access specifiers constructors and member initializer lists default member initializer(C++11) friend specifier explicit specifier converting constructor Special member function member functions default constructor copy constructor move constructor(C++11) copy assignment operator move assignment operator(C++11) destructor Inheritance base and derived classes virtual member functions override(C++11) final(C++11) pure virtual functions and abstract classes [edit] A non-static member function is a function that is declared in a member specification of a class without a static or friend static member function specifier. class S { int mf1(); // non-static member function declaration void mf2() volatile, mf3() &&; // can be cv-qualified and reference-qualified int mf4() const { return data; } // can be defined inline virtual void mf5() final; // can be virtual, can use final/override S() : data(12) {} // constructors are member functions too int data; }; int S::mf1() { return 7; } // if not defined inline, has to be defined at namespace Any function declarations are allowed, with additional syntax elements that are only available for non-static member functions: final and override specifiers, pure-specifiers, cv-qualifiers, ref-qualifiers, and member initialization lists. A non-static member function of class X may be called 1) For an object of type X using the class member access operator 2) For an object of a class derived from X 3) Directly from within the body of a member function of X 4) Directly from within the body of a member function of a c