I'm trying to extend an existing application using an agile library. The library forces me to create a concrete interface class, InterfaceToA
to interface to my application. However, within my application, the most natural place (without a major refactor) to instantiate this object is within another class's, say ClassA
, implementation. I really need the interface class to have access to all of ClassA
data and member functions as well (inherit from). So something like:
// Class declarations
class ClassA {
public:
double thing1;
double thing2;
f( double arg1, double arg2 );
ff()
};
class InterfaceToA : public ClassA {
public:
g( double arg1, double arg2 );
};
// Class implementations
double ClassA::f( double arg1, double arg2 ){
InterfaceToA interface;
return interface.g(arg1,arg2);
}
double ClassA::ff(){
return 1;
}
double InterfaceToA::g( double arg1, double arg2 ){
return (arg1 + thing1) - (arg2 + thing2) + ff();
}
//Main function
int main(){
ClassA myClassA;
myClassA.thing1 = 1;
myClassA.thing2 = 3;
double output;
output = myClassA.f(5,1);
std::cout << str(output) << std::endl;
return 0;
}
where in this case the expected output
would be 3
, (5+1) - (1+3) + 1 = 3
. Is this possible in C++, I've been trying to think about this using both inheritance and nested classes, but I can quite figure out how to proceed.