I have the following code that compiles fine under in Visual Studio and g++ but in Clang I get the error "error: 'ns::B' is an incomplete type"
A.h
#pragma once
namespace ns
{
class B;
class A
{
friend class B;
class Inner
{
public:
int x;
Inner(int x) : x(x) {}
};
public:
template<typename T>
T getB(int i)
{
B b = B(Inner(i));
return T(b);
}
};
}
B.h
#pragma once
#include "A.h"
namespace ns
{
class B
{
A::Inner i;
public:
B(A::Inner i) : i(i)
{}
operator int() const
{
return i.x;
}
};
}
main.cpp
#include "A.h"
#include "B.h"
int main()
{
ns::A a;
return a.getB<int>(5);
}
From my understanding the code should work because by the time the template get instantiated, B is complete. Is this correct? And if so, is there any way to work around the issue in Clang?
See Question&Answers more detail:os