I have an pre-defined pure abstract class which I don't want to touch. It's declared like:
class A {
public:
inline virtual ~A();
A(const A&);
A operator=(const A&);
virtual void someMethod();
};
The class has no member variables & none of these functions are having any implementation, so it should be equal to: virtual void someMethod() = 0;
.
I want to implement this pure abstract class in my own class (because I need to add member variables to implement the function someMethod()
) without changing the declaration from class A
, but there are two problems:
1.) class A
has no default constructor, but only a copy-constructor and assignment operator declared. So I won't be able to create an instance from my subclass, because A::A: no appropriate default constructor available
.
2.) Even assuming, class A
would have a default constructor declared and defined (If I add A(){}
to the class declaration), I would get 2 linker errors for someMethod() and destructor from class A
.
My own code looks like:
#include <memory>
class B : public virtual A {
public:
B() {}
inline virtual ~B() {}
B(const B&) {}
virtual void someMethod() override {}
};
int main(int argc, char*argv[]) {
auto object = std::make_unique<B>(B());
return 0;
}
Any advice what I'm doing wrong here?