Does C++ have feature that absorb all functions of another class in some ways?
More specifically, D
want to absorb all B
's functions that is public
and have C*
as the first parameter.
#include <iostream>
using namespace std;
class C{public: int va=2;};
class B{
public:
void f1(C* cPtr,int p,float q){ std::cout<<(cPtr->va+p)<<std::endl; }
int f2(C* cPtr,std::string str){ std::cout<<(cPtr->va)<<std::endl; return cPtr->va+100; }
//f3,f4, ....
};
class D{//absorber
public: static D construct(B* bPtr,C* cPtr){
????
}
?????
};
int main() {
C* cPtr=new C();
B* bPtr=new B();
D d=D::construct(bPtr,cPtr);
d.f1(2,3.0); //will call : bPtr->f1(cPtr,2,3.0)
int k=d.f2("f2"); //will call : bPtr->f2(cPtr,"f2")
return 0;
}
I know that I can do it per-function, using <...>
or manually.
Can I do it in a more automatic way (one piece of code, absorb all f1,f2,...
)?
If I can't, are there any similar features?
I may use it to comfort some calling.
There might be question about this, but I don't know a correct keyword to search for them.
Solution using macro is acceptable, but not much desirable.
A short answer like "No, and there are no similar features." is OK.