I have the class stickyNotes
, and in it I have the function addNote
which is a public non-static function.
In the code there is a new type defined:
typedef void(*fptr)
I also have the class Button
which in its constructor takes a variable of type fptr
, I have a function makeButton()
that returns a Button
object.
stickyNotes
also has another member called rendermainWindow
which renders the main window and adds a button, I am trying to create a new variable of type fptr
that is set to the address of stickyNotes::addNote
and I'm getting the error:
'&': illegal operation on bound member function expression
stickyNotes::rendermainWindow
:
void stickyNotes::rendermainWindow() {
/*
Renders the main window
*/
this->buttonList.empty(); // buttonList is a list of all buttons
mainWindow->clear(sf::Color(29, 29, 27, 255)); // clearing the window
sf::Vector2u windowDimensions = mainWindow->getSize(); // getting window dimensions
fptr cb = &this->addNote; <-------- ERROR HERE
Button plusB = makeButton((int)(windowDimensions.x * 0.75),
(int)(windowDimensions.y * 0.15),
(int)(windowDimensions.x * 0.85),
(int)(windowDimensions.y * 0.25),
mainWindow,
cb);
// first button to add stuff
std::vector<Button> vect;
vect.push_back(plusB);
this->buttonList.push_back(vect);
renderNotes();
}
What I've tried:
Replacing this->addNote
with stickyNotes::addNote
.
PS:
I'm not looking to make addNote static. and I want to keep it public, how can I make a button with the callback function of addNote? if there is a workaround, I'll be glad to hear it.