I’ve been reading about inheritance but I still dont have it 100% clear, here goes my question:
I have for example a class full of stuff:
class Something
{
public:
Something();
Something(int A);
Something(Something S);
~Something();
Something& operator=(const Something & s);
Something operator+(const Something & s) const;
// more methods ...
protected:
int A,B,C;
}
All methods implemented somewhere, and now I just want a new class to add one more attribute and maybe one method, but I still want the same behavior as the SuperClass (constructor, destructor, methods, operators), so I do something like this:
class SomethingMore : public Something
{
public:
void OnlyMethodHere();
private:
int D;
}
But I get something like:
undefined reference to SomethingMore::SomethingMore(int)
Is there a ay to tell the compiler to use everything just like it is in the SuperClass or do I have to make a SuperClass::method() in every child’s method?
You don’t have to repeat for methods. but for constructor, you have to define them properly in the sub class. Anyway the code is boiler plate unless you have anything extra.