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

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -