Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am defining all constants in a .h file.

Earlier it were
C++
#defines
. I am replacing it with
C++
const
.

Header file looks like

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

for this code i am getting the following error

error: expected unqualified-id before numeric constant|


for the line
C++
const int BASE = 0;
Posted
Comments
markkuk 9-Nov-12 4:23am    
Do you have a #define for BASE left somewhere in your code?
PrafullaVedante 9-Nov-12 4:37am    
Yupp .... its defined in another header file. Thanks ...


You got it right on first shot ... :) After removing the #define Code is compiling fine now ..

1 solution

The following program:

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



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

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


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


By the way, why don't you use an enum?
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900