I have been getting the following error with this code:
class A {
public:
static void st() {
(arr[5]->*n_st)();
};
void (A::*n_st)() {
};
private:
static A *arr[10];
};
int main()
{
return 0;
}
main.cpp: In static member function ‘static void A::st()’:
main.cpp:4:23: error: invalid use of member ‘A::n_st’ in static member function
4 | (arr[5]->*n_st)();
| ^~~~
main.cpp:6:19: note: declared here
6 | void (A::*n_st)() {
| ^~~~
I have laboriously looked for reasons and fixes to this error, but I cannot find similar code online. What is bugging me the most is that this code:
class A {
public:
static void st() {
arr[5]->n_st();
};
void n_st() {
};
private:
static A *arr[10];
};
int main()
{
return 0;
}
Compiles flawlessly. I thought the former code would compile as well.
What am I missing here? Which sort of code would make it work? It is crucial that n_st
remains of type
void (A::*)()
.
(PS: I am a bit of a noob, still learning pointers and such, so please be patient :D).