My simple code looks like:
a.cpp:
#include <iostream>
namespace asd
{
class B
{
public:
void ss()
{
extern int i;
std::cout << i;
}
};
}
int main()
{
asd::B e;
e.ss();
}
b.cpp:
int i = 4;
Is this code good with standard or no ? Visual Studio compiles it without errors but the Intel C++ compiler says: unresolved external symbol "int asd::i" (?i@asd@@3HA)
For more fun if i change b.cpp to:
namespace asd
{
int i = 4;
}
Then Visual Studio C++ 2013 says: unresolved external symbol "int i" (?i@@3HA)
But the Intel C++ compiler says ok :) What is the proper version of this code If I want to have this extern in class member function (is it legal ?) ?
Edit: The best results are, when we change b.cpp to:
namespace asd
{
int i = 4;
}
int i = 5;
Visual c++ prints 5, intel compiler 4 :)