c++ - Multi level inheritance -


i'm transferring java , i'm trying learn how write code in c++.

i have question according multi level inheritance abstract classes

i have pseudocode in java , want define similar structure using class interfaces in c++ constructors , destructors.

abstract class node {     public abstract void addchild(node child); }  abstract class stmtnode extends node {  }  class whilenode extends stmtnode {  } 

my question is: can me define such classes?

@edit have following classes:

class node { public:     explicit node();     virtual ~node() = 0;      virtual void addchild(node* child) = 0; };  class stmtnode : public node { public:     explicit stmtnode();     virtual ~stmtnode() = 0;      virtual void addchild(node* child) override; };  class whilenode : stmtnode { public:     explicit whilenode();     ~whilenode() override;       void addchild(node* child) override; }; 

are correct?

there no need define parameter less ctor explicit. explicit node(); can simplified removing explicit keyword;

don't forget provide implementation pure virtual destruction otherwise have undefined behavior in code.

inline node::~node() { } inline stmtnode::~stmtnode() { } 

because node , stmtnode have pure virtual function , act interface can define ctors protected.

there no need define destructions override keyword.


Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -