I have the following code that is compiling fine with VS2015, but not with gcc (any version). To me, the namespace of class A_Creator
is properly defined (i.e. root namespace) because is has been forward declared on top of the program. Why gcc cannot detect the namespace of the A_Creator
class properly? Which compiler is right?
#include <list>
class A_Creator;
namespace X
{
class A
{
private:
int mX;
A(int x) :
mX(x)
{}
// GCC complains about this line, and it should be changed to ::A_Creator
// On VS2015, both of them are working
friend class A_Creator;
};
} // namespace X
class A_Creator
{
public:
std::list<X::A> TestOnList(int z)
{
std::list<X::A> a_list;
a_list.push_back(X::A(z));
return a_list;
}
};
int main()
{
A_Creator a_cr;
auto x = a_cr.TestOnList(12);
}