1
class A {
virtual void fun2();
virtual void fun3() {};
};
int main() {
new A;
return 0;
}
//LNK2001: unresolved external symbol "private: virtual void __cdecl A::fun2(void)" (?fun2@A@@EEAAXXZ)
2
class A {
virtual void fun1()=0;
virtual void fun2();
virtual void fun3() {};
};
class B : A {
void fun1() override {}
};
class C : B {
void fun2() override {}
};
int main() {
new B;
return 0;
}
//LNK2001 : unresolved external symbol "private: virtual void __cdecl A::fun2(void)" (? fun2@A@@EEAAXXZ)
//B继承了A,实现了A中的纯虚函数fun1。A中的虚函数fun2没有实现。
//构造B对象前,先要构造A,A无法构造,导致无法构造B对象实例。
3
class A {
virtual void fun1()=0;
virtual void fun2();
virtual void fun3() {};
};
class B : A {
void fun1() override {}
void fun2() override {};
};
class C : B {
void fun2() override {}
};
int main() {
new B;
return 0;
}
//LNK2001: unresolved external symbol "private: virtual void __cdecl A::fun2(void)" (?fun2@A@@EEAAXXZ)
// B中实现了A中的虚函数fun2,还是无法构造成功。因为无法构造A对象。
4
class A {
virtual void fun1()=0;
virtual void fun2() {};
virtual void fun3() {};
};
class B : A {
void fun1() override {}
};
class C : B {
void fun2() override {}
};
int main() {
new B;
return 0;
}
//OK
5
class A {
virtual void fun1()=0;
virtual void fun2() {};
virtual void fun3() {};
};
class B : A {
void fun1() override {}
};
class C : B {
};
int main() {
new C;
return 0;
}
//OK
6
class A {
virtual void fun1()=0;
virtual void fun2();
virtual void fun3() {};
};
class B : A {
void fun1() override {}
};
class C : B {
void fun2() override {}
};
int main() {
new C;
return 0;
}
//LNK2001: unresolved external symbol "private: virtual void __cdecl A::fun2(void)" (?fun2@A@@EEAAXXZ)
//虽然C中实现了A中的虚函数fun2。
//构造C对象前,先要构造B对象,构造B对象前,要先构造A,无法构造A,导致无法构造C对象。
7
class A {
virtual void fun1()=0;
virtual void fun2();
virtual void fun3() {};
};
class B : A {
void fun1() override {}
void fun2() override {};
};
class C : B {
void fun2() override {}
};
int main() {
new C;
return 0;
}
//LNK2001: unresolved external symbol "private: virtual void __cdecl A::fun2(void)" (?fun2@A@@EEAAXXZ)