I am stuck on a point at my C++ personal learning process. I come from Java language.
I am trying to set a class in C++ which have an abstract method. Up to there, there is no big deal. But I'd like to instantiate that class as I can do in Java:
// MyClass has an abstract method named "AbstractMethod"
MyClass class_object = new MyClass()
{
@Override
public void AbstractMethod()
{
// Do something here
}
};
class_object.AbstractMethod();
In Java, it works perfectly. But i'd like to do the same in C++, and there is a problem here: C++ doesn't seems to like the idea of instantiating a class having virtual method.
I have searched for some days now and I can't find any answer to that question on internet. Maybe it is just me badly writting the search sentence, as I am not a native English speaker I might have some difficulties finding the correct syntax on asking that question.
Is there any possibility for me, in C++, to do as in Java or at least, likely? Is using Templates a solution ? (never learned templates before, I still have a lot to learn).
Also, I cannot create numerous classes to redefine a method, as this class will be used to do a custom treatment for each instance. It would be, I think, a waste to create classes just to see it being the proud father of one and only one object of that type.