错误:数值常量前应有预期的unqualid-id [英] error: expected unqualified-id before numeric constant

查看:207
本文介绍了错误:数值常量前应有预期的unqualid-id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在.h文件中定义所有常量.

之前是

Hi,

I am defining all constants in a .h file.

Earlier it were

#defines

.我将其替换为

const

.

头文件看起来像

.

Header file looks like

namespace preprocessing
{
    namespace generaldef
     {
          const int BASE = 0;
     }
}


对于此代码,我得到以下错误

错误:数字常量前应有预期的unqualid-id |


对于行


for this code i am getting the following error

error: expected unqualified-id before numeric constant|


for the line

const int BASE = 0;

推荐答案

以下程序:

The following program:

// foo.h
namespace preprocessing
{
    namespace generaldef
     {
          const int BASE = 0;
     }
}







// foo.cpp
#include "foo.h"
#include <iostream>

using namespace std;
int main()
{
  cout << preprocessing::generaldef::BASE << endl;
}



使用gcc版本4.4.5可以正常编译(并运行!).


顺便说一句,为什么不使用enum?



Compiles (and runs!) fine with gcc version 4.4.5.


By the way, why don''t you use an enum?


这篇关于错误:数值常量前应有预期的unqualid-id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆