c++ - a class inheritance hierarchy design issue -


i have following class hierarchy graphs:

typedef vector<int> arrayi; typedef vector<array<long>> mat2db; typedef vector<arrayi> adjlist;  class basegraph {     int nodes;     arrayi degree;     //some member functions. }  class matgraph: public basegraph {     mat2db matrix;     //member functions. }  class lmatgraph: public matgraph {     arrayi labels;     //member functions. }  class listgraph: public basegraph {     adjlist list;     //member functions. }  class llistgraph: public listgraph {     arrayi labels;     //member functions. } 

now in class have many other functions, virtual, when call proper function while using base class pointer.

for example have function sssp(int node) implements single source shortest path. implementation both different class matgraph , class listgraph adjacency matrix representation , adjacency list representation of graphs respectively. there not need change definition labelled version of these graphs not define these functions again in llistgraph , lmatgraph

now problem havin setlabel(const arrati &) in llistgraph , lmatgraph classes. need function virtual gets called through base class pointer, @ same time not have such labels classes matgraph , listgraph.

i not know if design hierarchy correct or not, seemed intuitive me. comments on good. can setlabel function. okay have such function(to me looks kind of workaround question) or need reconsider class hierarchy.

p.s.: love if there books can practice design questions these. run these delimma offten , not sure of them.

edit:

use of class graph used in class clustering have member basegraph *graph i.e.

class clustering {     basegraph *graph; } 

i storing pointer base class here can use different algorithms(implemented functions) class graph. clustering class again depends type of graph want use.

maybe ?

typedef vector<int> arrayi; typedef vector<array<long>> mat2db; typedef vector<arrayi> adjlist;  class basegraph {     int nodes;     arrayi degree;     virtual void sssp(int node);     //some member functions. }  class labeledgraph: public virtual basegraph {     arrayi labels;     virtual void setlabel(const arrati &);     //member functions. }  class matgraph: public virtual basegraph {     mat2db matrix;     //member functions. }  class lmatgraph: public virtual matgraph, public virtual labeledgraph {     //member functions. }  class listgraph: public virtual basegraph {     adjlist list;     //member functions. }  class llistgraph: public virtual listgraph, public virtual labeledgraph {     //member functions. } 

i'm assuming here incorrectly inherited graph when should have been inheriting basegraph (typeo) - though if not comes down same point.

also rough coding, if have questions or if there mistakes feel free ask.


Comments