I
ik
Hello All,
I am facing a problem as follows.
I have a header file called myNameSpace.h which as the following
contents.
//Header file .. myNameSpace.h
namespace myNameSpace {
static int iMyInt = 0;
};
And my source file, as follows.
// Source file myNameSpace.cpp
#include "myNameSpace.h"
myNameSpace::iMyInt = 0;
int main(int argc, char* argv[])
{
return 0;
}
This gives me a compiler error.. on MingW.
D:/users/others/cpp_trials/SimplePrograms/myNameSpace.cpp:5: ISO C++
forbids declaration of `iMyInt' with no type
D:/users/others/cpp_trials/SimplePrograms/myNameSpace.cpp:5:
redefinition
of `int myNameSpace::iMyInt'
D:/users/others/cpp_trials/SimplePrograms/myNameSpace.h:5: `int
myNameSpace::iMyInt' previously defined here
at the same time ..
#include "myNameSpace.h"
int main(int argc, char* argv[])
{
myNameSpace::iMyInt = 0;
return 0;
}
This compiles..
I understand it is true for any variable declaration, at the global
namespace. Once declared any other reinitalization, is taken as a
re-definition.
I would like to know what is the correct explanation to this ?
Any help will be appreciated.
Thanks in Advance
~Ik
I am facing a problem as follows.
I have a header file called myNameSpace.h which as the following
contents.
//Header file .. myNameSpace.h
namespace myNameSpace {
static int iMyInt = 0;
};
And my source file, as follows.
// Source file myNameSpace.cpp
#include "myNameSpace.h"
myNameSpace::iMyInt = 0;
int main(int argc, char* argv[])
{
return 0;
}
This gives me a compiler error.. on MingW.
D:/users/others/cpp_trials/SimplePrograms/myNameSpace.cpp:5: ISO C++
forbids declaration of `iMyInt' with no type
D:/users/others/cpp_trials/SimplePrograms/myNameSpace.cpp:5:
redefinition
of `int myNameSpace::iMyInt'
D:/users/others/cpp_trials/SimplePrograms/myNameSpace.h:5: `int
myNameSpace::iMyInt' previously defined here
at the same time ..
#include "myNameSpace.h"
int main(int argc, char* argv[])
{
myNameSpace::iMyInt = 0;
return 0;
}
This compiles..
I understand it is true for any variable declaration, at the global
namespace. Once declared any other reinitalization, is taken as a
re-definition.
I would like to know what is the correct explanation to this ?
Any help will be appreciated.
Thanks in Advance
~Ik