⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cpp01.cpp

📁 C++参考书
💻 CPP
字号:

// Coded by plusir -- Jan.14.2003.
// Standard C++ Bible -- (P740-27-1)

#include <iostream>
#include <typeinfo>
using namespace std ;

class Shape
{
	public:
		virtual void foo( void ) const { } ;
} ;

class Circle : public Shape { } ;
class Rectangle : public Shape { } ;

void process( Shape * ) ;

int main()
{
	Circle circle ;
	process( &circle ) ;

	Rectangle rect ;
	process( &rect ) ;

	Shape shape ;
	process( &shape ) ;

	return 0 ;
}

void process( Shape *sp )
{
	Circle *cp = dynamic_cast<Circle*>( sp ) ;
	if ( cp != NULL ) {
		cout << "Processing a Circle." << endl ;
		return ;
	}

	Rectangle *rp = dynamic_cast<Rectangle*>( sp ) ;
	if ( rp != NULL ) {
		cout << "Processing a Rectangle." << endl ;
		return ;
	}

	cout << "Unknown Shape, cannot process" << endl ;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -