您的位置:首页 > 其它

关于构造函数的一些新的认识

2007-05-04 11:12 417 查看
// testconstructor.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

class Test
{
public:
Test(int)
{
cout << "constructor function of parameter int has been called" << endl;
}

Test()
{
cout << "The default constructor function has been called" << endl;
}

void fun()
{
cout << "fun() has been called" << endl;
}

~Test()
{
cout << "The Destructor function has been called" << endl;
}
};

int main( void )
{
Test objA(1);
objA.fun();

Test objB();

// objB.fun();
}

VS.Net 2003 运行结果:

constructor function of parameter int has been called
fun() has been called
The Destructor function has been called
Press any key to continue

结论:

Test objB(); //仅仅只是函数声明
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: