写错是不对的:
class A {
public:
virtual ~A() = 0;
};
Run Code Online (Sandbox Code Playgroud)
对于抽象基类?
至少在MSVC中编译......它会在运行时崩溃吗?
我理解虚拟析构函数的必要性.但为什么我们需要纯虚拟析构函数?在其中一篇C++文章中,作者提到我们在创建类抽象时使用纯虚析构函数.
但是我们可以通过将任何成员函数设置为纯虚拟来使类抽象化.
所以我的问题是
我们什么时候才能真正使析构函数变为虚拟?任何人都能给出一个很好的实时例子吗?
当我们创建抽象类时,将析构函数设置为纯虚拟是一种很好的做法吗?如果是..那为什么?
我正在使用Eclipse-CDT在Ubuntu x64上设置一个C++项目.我基本上是在打招呼世界并链接到商业第三方图书馆.
我已经包含了链接到其库的头文件,但我仍然遇到链接器错误.除了明显的问题之外,这里是否存在一些可能的问题(例如我99%肯定我正在链接到正确的库).
Eclipse说:
Building target: LinkProblem Invoking: GCC C++ Linker g++ -L/home/notroot/workspace/somelib-3/somelib/target/bin -o"LinkProblem" ./src/LinkProblem.o -lsomelib1 -lpthread -lsomelib2 -lsomelib3 ./src/LinkProblem.o: In function `main': /home/notroot/workspace/LinkProblem/Debug/../src/LinkProblem.cpp:17: undefined reference to `SomeClass::close()' ./src/LinkProblem.o: In function `SomeOtherClass': /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:148: undefined reference to `SomeClass::SomeClass()' /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:148: undefined reference to `vtable for SomeOtherClass' /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:151: undefined reference to `SomeClass::~SomeClass()' ./src/LinkProblem.o: In function `~SomeOtherClass': /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:140: undefined reference to `vtable for SomeOtherClass' /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:140: undefined reference to `SomeClass::~SomeClass()' /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:140: undefined reference to `SomeClass::~SomeClass()' collect2: ld returned 1 exit status make: *** …