相关疑难解决方法(0)

gcc和clang在运算符重载解析期间隐式实例化模板参数

考虑以下代码:

struct A; // incomplete type

template<class T>
struct D { T d; };

template <class T>
struct B { int * p = nullptr; };

int main() {
    B<D<A>> u, v;
    u = v;  // doesn't compile; complain that D<A>::d has incomplete type
    u.operator=(v); // compiles
}
Run Code Online (Sandbox Code Playgroud)

演示.由于u.operator=(v)编译但u = v;没有,在后一个表达式的重载解析期间,编译器必须已经隐式实例化D<A>- 但我不明白为什么需要实例化.

为了使事情更有趣,这段代码编译:

struct A; // incomplete type

template<class T>
struct D; // undefined

template <class T>
struct B { int * p …
Run Code Online (Sandbox Code Playgroud)

c++ gcc templates clang

32
推荐指数
1
解决办法
1090
查看次数

标签 统计

c++ ×1

clang ×1

gcc ×1

templates ×1