文章内容请参加:http://www.cppblog.com/izualzhy/archive/2012/09/17/190998.html。
以下是我自己写的一个测试用的例子:
test.h
#ifndef __test_h__
#define __test_h__
#include <iostream>
class Base
{
public:
Base() { init(); }
protected:
virtual void init() { std::cout << "base::init()" << std::endl; }
};
class Inherit : public Base
{
public:
Inherit() : Base() {}
protected:
void init() { std::cout << "Inherit::init()" << std::endl; }
};
#endif // __test_h__
main.cpp
#include "test.h"
int main( void )
{
Inherit i;
return 0;
}
程序运行结果: