Advertisement
Josif_tepe

Untitled

Apr 27th, 2021
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Zivotno {
  5. private:
  6.     char ime[50];
  7. public:
  8.     Zivotno() {
  9.        
  10.     }
  11.     Zivotno(char *c) {
  12.         strcpy(ime, c);
  13.     }
  14.     virtual void print_name() {
  15.         cout << "Zivotno: " << ime << endl;
  16.     }
  17.     void f(int x, int y) {
  18.         cout << x << " " << y << endl;
  19.     }
  20.     virtual ~Zivotno() {
  21.        
  22.     }
  23. };
  24. class Kuce : public Zivotno {
  25. private:
  26.     char rasa[50];
  27. public:
  28.     Kuce() {
  29.        
  30.     }
  31.     Kuce(char *ime, char *r) : Zivotno(ime) {
  32.         strcpy(rasa, r);
  33.     }
  34.     void print_name() override {
  35.         cout << "Rasa: " << rasa << endl;
  36.     }
  37.     void f(int x) {
  38.         cout << x << endl;
  39.     }
  40.     ~Kuce() {
  41.        
  42.     }
  43. };
  44. int main() {
  45.     Zivotno *z = new Zivotno("kuce");
  46.  
  47.     if(dynamic_cast<Kuce*>(z)) {
  48.         cout << "kuce" << endl;
  49.     }
  50.     else {
  51.         cout << "zivotno" << endl;
  52.     }
  53.    
  54.     return 0;
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement