DM560, Introduction to Programming in C++
Task 1
#include<iostream>
using namespace std;
class B1 {
public:
virtual void vf() {cout<<__PRETTY_FUNCTION__<<endl;};
void f() {cout<<"B1:f()"<<endl;};
//virtual void pvf() = 0;
};
class D1 : public B1 {
public:
void vf() override {cout<<__PRETTY_FUNCTION__<<endl;};
//void f() {cout<<"D1:f()"<<endl;};
};
class D2 : public D1 {
public:
//void pvf() override {cout<<__PRETTY_FUNCTION__<<endl;};
};
class B2 {
public:
virtual void pvf() = 0;
};
class D21 : public B2 {
public:
void pvf() override {cout<<s<<endl;};
private:
string s="ciao";
};
class D22 : public B2 {
public:
void pvf() override {cout<<i<<endl;};
private:
int i=23;
};
void f(B2 &b) {
b.pvf();
}
int main (int argc, char **argv) {
/*
cout << "Task. 1"<<endl;
B1 b1;
b1.vf();
b1.f();
cout << "Task. 2"<<endl;
D1 d1;
d1.vf();
d1.f();
cout << "Task. 3"<<endl;
B1& b2=d1;
b2.vf();
b2.f();
cout << "Task. 6"<<endl;
D2 d2;
d2.f();
d2.vf();
d2.pvf();
*/
cout << "Task. 7"<<endl;
D21 d21;
D22 d22;
f(d21);
f(d22);
exit(EXIT_SUCCESS);
}