#include <iostream>
class Base{
public:
virtual void do_something()
{
std::cout<<"Person"<<std::endl;
}
virtual void print_self() final
{
std::cout<<"Person"<<std::endl;
}
};
class SubClass1 : public Base{
public:
void do_something() override
{
std::cout<<"SubClass1"<<std::endl;
}
};
void test1()
{
SubClass1 *sc = new SubClass1;
Base *base = sc;
base->do_something();
}
class SubClass2 final : public Base{
public:
void do_something() override
{
std::cout<<"SubClass2"<<std::endl;
}
};
void test2()
{
SubClass2 *sc = new SubClass2;
Base *base = sc;
base->do_something();
}
class SubClass3 : public SubClass2{
public:
};
class SubClass4 : public Base{
public:
virtual void print_self()
{
std::cout<<"Person"<<std::endl;
}
};
class Magic {
public:
Magic() = default;
Magic& operator=(const Magic&) = delete;
Magic(int magic_number);
}
int main()
{
test1();
test2();
return 0;
}
|