Answer the question
In order to leave comments, you need to log in
How to make a "redefinition" of a function in c++?
Good day, I immediately ask you not to throw slippers.
Suppose I have some kind of Enemy class that has an update function , how can I make it so that I can "override" it, I know that the term is not particularly correct, I hope it will be clearer with an example code.
#include <iostream>
class Enemy {
public:
void update() {
}
}
int main(int argc, char* argv[]) {
Enemy enemy;
/*И тут к примеру как нибудь так*/
enemy::update() {
std::cout << "Hello";
}
return 0;
}
Answer the question
In order to leave comments, you need to log in
Your question can be solved in this way.
#include <iostream>
#include <functional>
class Enemy final
{
public:
std::function<void()> update = []() {};
};
int main( int argc, char* argv[] )
{
Enemy enemy;
enemy.update = []() { std::cout << "Hello"; };
enemy.update();
return 0;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question