看起来很奇怪。在这里您可以看到错误消息是一种类型之间发生转换并且失败。如果我从 Vector3 的复制构造函数中删除显式修饰符,那就很好,没有错误。有人可以解释为什么吗?我很困惑。
template<typename T>
class Vector3 {
public:
explicit Vector3(const Vector3& v) :x(v.x), y(v.y), z(v.z) {}
Vector3() :x(0), y(0), z(0) {}
T x, y, z;
};
template<typename T>
Vector3<T> getVec3() {
return Vector3<T>(); //c2440 "return":cannot convert Vector3<int> to Vector3<int>
}
int main()
{
getVec3<int>();
}
Run Code Online (Sandbox Code Playgroud) class test {
public:
test(int i) : t(10) {
cout << "cst" << i << endl;
}
static test ins;
const test t;// 1
};
Run Code Online (Sandbox Code Playgroud)
在第 1 行,编译器失败并出现错误:
不允许不完整的类型
这是为什么?