有没有 &typeid(T) != &typeid(T) 的时候?
我主要对 Windows 的编译器感兴趣,但也感谢 Linux 和其他平台的任何信息。
是的。因此,在 windows 下 DLL 不能有未解析的符号。如果你有:
foo.h
struct foo { virtual ~foo() {} };
dll.cpp
#include "foo.h"
...
foo f;
cout << &typeid(&f) << endl
主文件
#include "foo.h"
...
foo f;
cout << &typeid(&f) << endl
会给你不同的指点。因为在加载 dll 之前 typeid(foo) 应该存在于 dll 和主 exe 中
More then that, under Linux, if main executable was not compiled with -rdynamic (or --export-dynamic) then typeid would be resolved to different symbols in executable and
in shared object (which usually does not happen under ELF platforms) because of some optimizations done when linking executable -- removal of unnecessary symbols.