Hello there. Finally decided to make an account here :)
Anyways, I just started trying to implement function pointers in my code, and I seem to be having a few issues. (this is, of course, test code):
#include <iostream>
using namespace std;
class MyClass;
class SomeClass
{
public:
SomeClass();
MyClass* test;
int SomeFunc(int x, char* y);
};
class MyClass
{
public:
int (SomeClass::*funcptr)(int, char*);
};
int SomeClass::SomeFunc(int x, char* y)
{
cout << "int x: " << x << endl;
cout << "char* y: " << y << endl;
return 0;
}
int main(int argc, char* argv[])
{
SomeClass* someclass = new SomeClass();
someclass->test->funcptr = &SomeClass::SomeFunc;
(someclass->test->*funcptr)(2, "Lol"); // C2065: 'funcptr': undeclared identifier
return 0;
}
Something tells me that this is functionality that I cannot do? And if so, I seem to be doing it wrong.
Basically, I have two classes: SomeClass and MyClass. MyClass right now just has a function pointer. SomeClass has a member function that I want MyClass to point to. However, trying to call that function seems to not be working the way I wanted it to. In fact, it's not working.
Any suggestions?