main.cpp

来自「斯坦福Energy211/CME211课《c++编程——地球科学科学家和工程师》」· C++ 代码 · 共 48 行

CPP
48
字号
#include <iostream>#include "employee.h"#include "hourly.h"#include "salaried.h"using namespace std;int main() {		// Dynamically create a new Hourly object.	// The new operator returns a pointer to the object.	Hourly *ph = new Hourly( "James Lambers", 		"010-10-1010", 20.0, 40 );		// Now we do the same with a Salaried object, except	// we use a smart pointer, which we don't have to 	// remember to delete	auto_ptr<Salaried> ps(new Salaried( "Margot Gerritsen",		"987-65-4321", 7000.0 ));			// We can't create an Employee object, but we can	// have a pointer to an Employee object	Employee *pe = ph;		// Output the Hourly object, accessing it through	// the Employee pointer	cout << "First Employee:" << endl;	cout << "===============" << endl;	cout << *pe;	cout << endl;		// Then output the Salaried object	cout << "Second Employee:" << endl;	cout << "================" << endl;	cout << *ps;				// The Hourly object is not stored in a smart pointer,	// so we have to delete it.  We can access it through	// the Employee pointer, and because the Employee	// destructor is virtual, the Hourly destructor will	// be called too	delete pe;		return 0;}

⌨️ 快捷键说明

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