C++如何防止类被继承(一)
#include <iostream>
using namespace std;
template <class T>
class Assistant
{
private:
friend T;
Assistant(){};
~Assistant(){};
};
class Animal:virtual public Assistant<Animal>
{
public:
Animal(){};
~Animal(){};
void ShowType();
void Eat();
void Walk();
void Sleep();
};
void Animal::ShowType()
{
cout << "Animal" << endl;
}
void Animal::Eat()
{
}
void Animal::Walk()
{
}
void Animal::Sleep()
{
}
//class Cow:public Animal//无法继承Animal
//{
//};
void main()
{
Animal animal = Animal();
animal.ShowType();
// Cow cow = Cow();
int tem;
cin >> tem;
}