【发布时间】:2014-09-19 01:53:58
【问题描述】:
如何编译下面的代码?
#include <type_traits>
#include <utility>
struct A;
template<typename T>
struct B{
T* p;
B& operator=(B&&);
B& operator=(T&&);
};
int main(){
//typedef B<A> type;// fine
typedef B<std::pair<A, A>> type;// error
noexcept(std::declval<type&>() = std::declval<type>());
return 0;
}
PS:Type B 模拟 boost::recursive_wrapper,同样原因编译失败。
【问题讨论】:
-
17.6.4.8/2 特别是,在以下情况下效果未定义: ... --如果使用不完整类型 (3.9) 作为模板参数实例化模板组件时,除非该组件特别允许。
-
@IgorTandetnik typedef 本身不应该实例化
std::pair<A, A>。 -
是否可以选择将
B设为模板并将A设为模板参数? -
@jxh typedef 不是需要完整类型的上下文。
-
@5gon12eder 我编辑代码以使用模板。