Overwriting virtual functions in body of code
I have a question about virtual functions in C++. I have spent the last
hour searching but I'm getting nowhere quickly and I was hoping that you
could help.
I have a class that handles transmitting and receiving data. I would like
the class to be as modular as possible and as such I would like to make an
abstract/virtual method to handle the received messages.
Although I know I could create a new class and overwrite the virtual
method, I don't really want to have to create a large array of new classes
all implementing the method different ways. In Java you can use listeners
and/or override abstract methods in the body of the code when declaring
the object as can be seen in the example.
JTextField comp = new JTextField();
comp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
//Handler Code
}
});
Is this possible in C++ or is there a better approach to this sort of
problem?
Cheers and Many thanks in advance,
Chris.
No comments:
Post a Comment