|
|

楼主 |
发表于 2004-10-27 15:18:00
|
显示全部楼层
Re:[C++语法]一个特殊的问题?
问题发现了,但是...非常迷惑,先看下列代码.
#include<iostream>
using namespace std;
class A
{
public:
A(void){cout<<"A Created!"<<endl;}
~A(void){cout<<"A Destroyed!"<<endl;}
};
class B
{
public:
B(void){cout<<"B Created!"<<endl;}
~B(void){cout<<"B Destroyed!"<<endl;}
};
A a1;
void main(int p1,char* p2[])
{
cout<<"In Main!"<<endl;
A a2;
}
B b1;
将输出
A Created!
B Created!
In Main!
A Created!
A Destroyed!
而这个
#include"iostream.h"
//using namespace std;
class A
{
public:
A(void){cout<<"A Created!"<<endl;}
~A(void){cout<<"A Destroyed!"<<endl;}
};
class B
{
public:
B(void){cout<<"B Created!"<<endl;}
~B(void){cout<<"B Destroyed!"<<endl;}
};
A a1;
void main(int p1,char* p2[])
{
cout<<"In Main!"<<endl;
A a2;
}
B b1;
确输出了:
A Created
B Created
in main
A Created
A Destroyed
B Destroyed
A Destroyed
Press any key to continue...
注意他们的差别在头两行,为什么会这样??????
|
|