lang模板不完整类型 [英] Clang template incomplete type
本文介绍了lang模板不完整类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码可以在Visual Studio和g ++中正常编译,但是在Clang中出现错误错误:'ns :: B'是不完整的类型
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"
Ah
#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);
}
};
}
Bh
#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);
}
根据我的理解,代码应该可以正常工作,因为在实例化模板时, B完成。这样对吗?如果是这样,有什么办法可以解决Clang中的问题?
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?
推荐答案
程序格式错误,无法诊断
The program is ill-formed, no diagnostic required.
程序格式错误,无需诊断,如果:
The program is ill-formed, no diagnostic required, if:
- [...]
- 模板定义后的假想实例化将由于以下原因而形成错误:
- [...]
这篇关于lang模板不完整类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文