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;

}

posted @ 2013-06-12 19:22  Predator  阅读(157)  评论(0编辑  收藏  举报