employ.cpp
来自「经典vc教程的例子程序」· C++ 代码 · 共 33 行
CPP
33 行
// Fig. 9.5: employ.cpp
// Member function definitions for class Employee
#include <string.h>
#include <iostream.h>
#include <assert.h>
#include "employ.h"
// Constructor dynamically allocates space for the
// first and last name and uses strcpy to copy
// the first and last names into the object.
Employee::Employee( const char *first, const char *last )
{
firstName = new char[ strlen( first ) + 1 ];
assert( firstName != 0 ); // terminate if not allocated
strcpy( firstName, first );
lastName = new char[ strlen( last ) + 1 ];
assert( lastName != 0 ); // terminate if not allocated
strcpy( lastName, last );
}
// Output employee name
void Employee::print() const
{ cout << firstName << ' ' << lastName; }
// Destructor deallocates dynamically allocated memory
Employee::~Employee()
{
delete [] firstName; // reclaim dynamic memory
delete [] lastName; // reclaim dynamic memory
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?