vendredi 27 septembre 2019

Looping on table and showing a specific subclass member C++

I want to do a for loop on the table tab. In each iteration, I would like to check the type of the current element.

If it is an instance of B class then I print b, c otherwise.

Thank you for your help.

class A {} 
class B: public A {
  private int b; 
  // constructor + getter + setter 
} 
class C: public A { 
  private int c; 
  // constructor + getter + setter 
} 
// in the main 
B obj1(val1); 
C obj2(val2); 
A tab [] = {obj1, obj2}; 

Aucun commentaire:

Enregistrer un commentaire