Answer the question
In order to leave comments, you need to log in
Specifying the type of a C++ child class?
I have a partially abstract class and several of its children (let's call them A, A1, A2, .. respectively).
In one method A, I need to define the "id" of the class from which it is called. If called from an instance of A1, then this value is 1, for A2, and so on. for A, this value is not required to be defined (well, or it is simply 0).
To do this, I found two solutions:
1:
//A:
friend virtual int getType() = 0;
//A1:
int getType() {
return 1;
}
template<int D>
class A {
...
};
class A1 : public A<1>{
...
};
Answer the question
In order to leave comments, you need to log in
Templates are a completely applicable thing that is needed in the language and helps to solve a number of tasks, no problems in use - no
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question