// 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(); //仅仅只是函数声明