Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include< conio.h>
- using namespace std;
- class TestVirtual {
- public:
- virtual void functie() {
- cout << "print base class" << endl;
- }
- void functie3() {
- cout << "show base class" << endl;
- }
- };
- class TestMostenire : public TestVirtual {
- public:
- void functie() {
- cout << "print derivated class" << endl;
- }
- void functie3() {
- cout << "show derivaated class" << endl;
- }
- };
- void main() {
- TestVirtual *bptr, c;
- TestMostenire d;
- bptr = new TestVirtual();
- //Daca folosesti obiect de tipul clasei o sa folosesti automat functiile de le ai in clasa
- bptr->functie();
- bptr->functie3();
- //DACA FOLOSESTI OBIECT DE TIP POINTER DIN CLASA DE BAZA SI VREI SA ACCESZI CE AI IN DERIVATA ITI TREBUIE VIRTUAL
- bptr = &d;
- cout << endl;
- bptr->functie();
- bptr->functie3();
- cout << endl;
- //Daca folosesti obiect de tipul clasei o sa folosesti automat functiile de le ai in clasa
- d.functie();
- d.functie3();
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement