所以我正在复习一个测试,我正在看下面的代码:
#include<iostream>
using namespace std;
namespace acme
{
int map;
/* ** */enum day{one,two};
/* ** */void fun1(day d);
int cout; **
}
void main(){
acme::map = 1;
/* ** */void fun2(acme::day d);
cout << acme::map << endl;
using namespace acme;
map = 2;
/* ** */void fun3(day d);
std::cout << map << endl;
}我的问题是:在末尾用“**”表示的行是什么?比如,他们是做什么的?我排除了main中的一行星号,并且没有任何变化。
发布于 2013-11-07 11:44:56
{
int map; // an int named map.
/* ** */enum day{one,two}; // the words one and two that can be used like a type.
/* ** */void fun1(day d); // An empty function.
int cout; // - I have no idea why anyone would do this. Basically it an int named cout.
}我认为这样做的目的只是为了说明命名空间是如何阻止事物成为全局的。因此,如果它们位于不同的名称空间中,则可以使用相同名称的int。
发布于 2013-11-07 15:17:00
您注意到的所有以"void“开头的行都是函数声明。
例如:空function1(int x);
如果使用它们,则需要向它们添加函数定义。
例如:
void function1(int x)
{
cout<<x<<endl;
}"enum“是一种数据类型,它将其参数初始化为整数。(请仔细阅读)
https://stackoverflow.com/questions/19827140
复制相似问题