纯虚函数

#include <iostream>

namespace Virtual
{
	class CBase
	{
	public:
		CBase() {}
		virtual ~CBase() {}
		void testBase()
		{
			print();
		}

		virtual void print() = 0;
	};

	class CDived : public CBase
	{
	public:
		CDived() {}
		~CDived() {}
        
		void testDived() {testBase();}
		void print() {std::cout << "CDived's print() is called!\n";}
	};

	void fun()
	{
		CDived p;
		p.testDived();
	}
}

 

posted @ 2013-11-03 09:25  forgood  阅读(166)  评论(0编辑  收藏  举报