I'm trying to create a function pointer. My code:
Header file:
#pragma once
#include <stdio.h>
class my_class
{
private:
int function(int x);
int *(*foo)(int);
public:
my_class();
~my_class();
};
css file:
#include "my_class.h"
int my_class::function(int x) {
return 1;
}
my_class::my_class() {
foo = &function;
}
my_class::~my_class()
{
}
But the line inside my_class::my_class() gives this error:
error C2276: '&': illegal operation on bound member function expression
Putting the mouse cursor over the = in said line makes the following tooltip appear:
a value of type "int (my_class::*)(int x)" cannot be assigned to an entity of type "int *(*)int"
How can I get it to work?