So I have a vector of a struct object containing a function pointer to an external class.
//Menu.h
#include "Byte.h"
struct menuItem
{
Byte (Byte::*funcPoint)(Byte&);
string descript;
};
class Menu
{
private:
vector<menuItem> menuVect;
void runSelection(Byte&, Byte&);
public:
Menu();
void addMenu(string Description, Byte (Byte::*f)(Byte&));
void runMenu(Byte&, Byte&);
void waitKey();
};
I can assign new instances of function pointers as seen here:
void Menu::addMenu(string Description, Byte(Byte::*f)(Byte&))
{
menuVect.push_back({f, Description});
}
But when it comes time execute any given function within the vector, I get an error
void Menu::runSelection(Byte& bX, Byte& bY)
{
int select;
cin >> select;
if (select > 0 && select < menuVect.size() + 1) {
cout << bX.toInt();
menuVect.at(select - 1).funcPoint();
}
else
exit(0);
waitKey();
}
Not sure if its necessary, but I'll include main as well, as one of the function pointers being assigned to the vector
Main
#include "Menu.h"
int main()
{
Menu m;
Byte b1(7);
Byte b2(3);
m.addMenu("1. Func 1", Byte::add);
m.addMenu("2. Func 2", Byte::sub);
m.addMenu("3. Func 3", Byte::mul);
m.addMenu("4. Func 4", Byte::div);
m.runMenu(b1, b2);
return 0;
}
Byte Byte::add(int val)
{
Byte b(this->toInt() + val);
return b;
}
I have already found an obvious work around, by simply not having the functions within an object
The particular errors I'm getting are:
Error (active) E0109 expression preceding parentheses of apparent call must have (pointer-to-) function type
(field)std::vector Menu::menuVect
Error C3867 'Byte::add': non-standard syntax; use '&' to create a pointer to member
But nothing I find when I look this up helps.