I am learning C++ about incomplete-type.
I think this is impossible, but I am not sure.
Question:-
Is it possible to check inheritance between underlying type of 2 variables if both are incomplete types?
Test1.h:-
#include <vector>
class A{};
std::vector<A*> test1();
Test1.cpp:-
#include "Test1.h"
class B : public A{};
class C : public B{};
class D : public A{};
std::vector<A*> test1(){
A* b=new B(); A* c=new C(); A* d=new D();
std::vector<A*> re;
re.push_back(b); re.push_back(c); re.push_back(d);
return re;
}
Test2.cpp:-
#include "Test1.h"
int test2(){
std::vector<A*> v=test1();
A* b=v[0]; A* c=v[1]; A* d=v[2];
isInherit(b,c); //true
isInherit(c,d); //false
isInherit(b,d); //false
}
If the answer is yes, please show how to code bool isInherit(A*,A*).
Note that modifying class A is not allowed.
(Thus, a hack to set a non-static field of A into a variable by-type is not allowed.)
I may use it as some kinds of black-magic inside my code.
Aucun commentaire:
Enregistrer un commentaire