Advertisement
obernardovieira

Check if derivative is the class you want

Jan 21st, 2016
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using std::cout;
  4. using std::endl;
  5.  
  6. class caract {
  7.     int ID;
  8. public:
  9.     caract(int id) : ID(id) { }
  10.     ~caract() { }
  11.  
  12.     int getID() const { return ID; }
  13. };
  14.  
  15. class respira : public caract {
  16. public:
  17.     respira() : caract(1) { }
  18.     ~respira() { }
  19. };
  20.  
  21. class toxico : public caract {
  22. public:
  23.     toxico() : caract(2) { }
  24.     ~toxico() { }
  25. };
  26.  
  27. bool operator==(caract* c1, const caract& c2) {
  28.     return (c1->getID() == c2.getID());
  29. }
  30.  
  31. int main() {
  32.  
  33.     caract* c = new respira;
  34.  
  35.     if(c == respira())
  36.         cout << "sim" << endl;
  37.     else
  38.         cout << "nao" << endl;
  39.  
  40.     if(c == toxico())
  41.         cout << "sim" << endl;
  42.     else
  43.         cout << "nao" << endl;
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement