考虑以下代码:
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)