64,677
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <iostream>
using namespace std;
namespace abcd
{
//不需要全部引入名词空间 using namespace std;
using std::cout;
using std::endl;
class X
{
int x;
int xx;
public:
X(int a,int b){cout <<"X(int,int) called" <<endl;x = a; xx = b; }
~X(){cout <<"~X called" <<endl;}//是"{ }",不是"()"
X(){cout <<"X called" <<endl;x = 0; xx = 0;}
void set(int aa,int bb){x = aa; xx = bb;}
};
int abcde;
}
int _tmain(int argc, _TCHAR* argv[])
{
using namespace abcd;
abcd::X ax;
return 0;
}
#include <iostream>
using namespace std;
namespace abcd
{
using namespace std;
class X
{
int x;
int xx;
public:
X(int a,int b){
cout <<"X(int,int) called" <<endl;
x = a;
xx = b;
}
~X(){cout <<"~X called" <<endl;};//请注意这一行
X(){
std::cout <<"X called" <<endl;
x = 0;
xx = 0;
}
void set(int aa,int bb){
x = aa;
xx = bb;
}
};
int abcde;
}
int main()
{
return 0;
}