关于构造函数的一些新的认识
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(); //仅仅只是函数声明
//
#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(); //仅仅只是函数声明
相关文章推荐
- 关于学习与问题解决的一些认识
- 关于AOP的一些认识
- 关于Android原生Email的自己的一些认识
- 关于迭代器失效的一些认识
- 关于地质灾害防治的一些认识
- 关于数字证书和数字签名的一些认识
- 关于gcc内置函数和c隐式函数声明的认识以及一些推测
- 关于Invoke和BeginInvoke的一些认识
- tij学习笔记(关于构造函数的一些问题,this关键字)
- 关于指针引用的一些认识
- 关于c++的一些自我认识(1)
- 关于Cocos2d-x的一些认识(2)
- 关于JVM一些知识的粗浅认识
- 关于CCDirector的一些认识
- 关于final的一些认识
- 关于hessian的一些认识
- 关于构造函数继承的一些问题
- 关于C语言头文件保护的一些认识
- Android中关于JNI 的学习(一)对于JNIEnv的一些认识
- 关于GCD的一些认识