我在编译一些非常简单的代码时遇到了问题,我不知道它有什么问题:/看一下:
class A{
public:
virtual void func() = 0;
};
class B : public A
{
public:
virtual void func() {};
};
int main()
{
A* obj = new B();
return 0;
}这是我从g++得到的消息:
Info: resolving vtable for _cxxabiv1::__si_class_type_info by
linking to __imp __ZTVN10__cxxabiv120__si_class_type_infoE (auto-import)
Info: resolving vtable for __cxxabiv1::__class_type_info by
linking to __imp___Z TVN10__cxxabiv117__class_type_infoE (auto-import)
k:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe:
warning: auto-importing has been activated without
--enable-auto-import specified on the c ommand line. This should work
unless it involves constant data structures referencing symbols from
auto-imported DLLs发布于 2010-12-18 22:09:46
你在编译方面没有任何问题,你在链接方面有问题(更准确地说,只是警告)。请参见:
d:\alqualos\pr\testpq>g++ -Wall -c main.cpp
main.cpp: In function 'int main()':
main.cpp:14:8: warning: unused variable 'obj'
d:\alqualos\pr\testpq>g++ -Wall main.o
Info: resolving vtable for __cxxabiv1::__si_class_type_info by linking to __imp_
__ZTVN10__cxxabiv120__si_class_type_infoE (auto-import)
Info: resolving vtable for __cxxabiv1::__class_type_info by linking to __imp___Z
TVN10__cxxabiv117__class_type_infoE (auto-import)
d:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe: warning: a
uto-importing has been activated without --enable-auto-import specified on the c
ommand line.
This should work unless it involves constant data structures referencing symbols
from auto-imported DLLs.这是MinGW的一个广泛使用的“特性”。如果您的程序需要来自标准C++库的任何内容,甚至是简单的std::cout,就会发生这种情况。在这种情况下,它与vtables有关。要摆脱它:
d:\alqualos\pr\testpq>g++ -Wall -Wl,--enable-auto-import main.o我不知道“除非涉及引用来自自动导入的DLL的符号的常量数据结构”是什么意思。我试着用谷歌搜索了一下,但没有找到任何有用的东西。如果有人知道这到底是什么意思,什么时候可能是危险的,请在这里回复。
发布于 2010-12-18 20:54:24
尝试使用A * obj = new B;,但是以后也请发布错误消息。
发布于 2010-12-18 20:59:04
你在这里发布的代码符合C++标准的所有要求。所以问题出在编译器上,我试着用VS(Windows)和g++(Linux)编译,在这两个平台上都编译成功了。
https://stackoverflow.com/questions/4478090
复制相似问题