How to define a subclass of an abstract class so that it is concrete

1

With these classes:

class SerVivo {
 public:
  virtual void funcA() = 0;
  virtual void funcB() = 0;
};

class Vegetal : public SerVivo{
 public:
  virtual void funcB(){ cout << "funcB em Vegetal \n"; }
  virtual void funcC() = 0;
};

I wanted to know how I build the Tree class, derived from Vegetable, in order to build Tree-like objects.

    
asked by anonymous 20.02.2018 / 13:43

1 answer

0

You need to implement all the purely functions (defined as " virtual nome_da_duncao(...) = 0 ") of the hierarchy. Since Arvore is descendent of Vegetal , it must implement funcC . But since Vegetal is descendent of SerVivo , it also needs to implement funcA . You do not have to implement funcB because this has already been implemented in Vegetal.

Example:

class Arvore : public Vegetal {
public:
    void funcA() { cout << "funcA em Arvore \n"; }
    void funcC() { cout << "funcC em Arvore \n"; }
};


int main()
{

    Arvore arvore1{};
    arvore1.funcA();
    arvore1.funcB();
    arvore1.funcC();

    return 0;
}

Output:

funcA em Arvore                                                                                                                                                                             
funcB em Vegetal                                                                                                                                                                            
funcC em Arvore


...Program finished with exit code 0
    
21.02.2018 / 01:04