class Boy
{
public:
Boy()
{
cout << "Boy()" << endl;
m_age = 10;
}
void showAge()
{
cout << "my age is: " << m_age << endl;
}
private:
int m_age;
};
2.main函数调用类
int _tmain(int argc, _TCHAR* argv[])
{
cout << "---------------a------------------" <<endl;
Boy* a = new Boy; a->showAge();
cout << "---------------b------------------" <<endl;
Boy* b = new Boy(); b->showAge();
cout << "---------------c------------------" <<endl;
Boy c; c.showAge();
cout << "---------------d------------------" <<endl;
Boy d(); //申明一个返回类型为Boy,参数为空,名字叫做d的函数
return 0;
}
3.输出结果
---------------a------------------
Boy()
my age is: 10
---------------b------------------
Boy()
my age is: 10
---------------c------------------
Boy()
my age is: 10
---------------d------------------
请按任意键继续. . .
4.结束
Boy* a = new Boy;
Boy* b = new Boy();
Boy d(); //没意义