I have following third-party class(just wrapper around some pointer):
// a.h
class AImpl;
class A
{
AImpl* pImpl;
public:
A(): pImpl(0) {}
A(AImpl* ptr): pImpl(ptr) {}
...
AImpl* getImpl() const { return pImpl; }
...
void someMethodOfA();
};
I want to modify A
's interface: disable some methods, add some new, while hiding its implementation details. I decided to do following:
// new_a.h
class AImpl;
class A;
class NewA
{
AImpl* pImpl;
public:
NewA( const A& a );
...
void newMethodOfA();
...
};
//new_a.cpp
#include "a.h"
NewA::NewA( const A& a ): pImpl( a.getImpl() ) {}
...
void NewA::newMethodOfA()
{
A( pImpl ).someMethodOfA();
}
...
Is it ok to do so? Maybe there is better solution? I want to change A
interface because it doesn't fit my needs and don't want to keep it in my own code.