第1个回答 2017-01-16
可以,加一层括号。例子如下:
#include<iostream>
#include<iomanip>
using namespace std;
#include<stdio.h>
main()
{
int num;
{
class Owner
{
private: char name[20]; int mobile;
public:
Owner(char *n, long int m)
{ strcpy(name,n); mobile = m; };
char* getName(){ return name; };
long int getMobile(){return mobile; };
}; // end class
class Owner XX("John",12345);
num = XX.getMobile();
}
printf("num=%d\n",num);
return 0;
}
输出:
num=12345