开发者

typeid result across different dll's

I have two dlls which both declare a templated type, let's call A开发者_StackOverflow社区. If the declaration of A is sufficiently intricate, it happens that the result of typeid(A).name() is different when called in functions in two different dll's.

example:

DLL1:

struct MyType: public A< TEMPLATE_LIST_OF_A >{}

void f(){
std::string name1 = typeid(A).name();
}

DLL2:

struct MyType: public A< TEMPLATE_LIST_OF_A >{}
    void f(){
    std::string name2 = typeid(A).name();
    }

for example name1 could be something like: "???MyType??? etc" while name2 could be "???A??TEMPLATE_LIST_OF_A etc".

Which actually makes quite sense to me, but is there is a way, provided that the names used are the samem to guarantee that name1==name2 ?

thanks, rob


Not only is there no way to guarantee that typeid().name() is the same in different DLLs, the standard makes almost no guarantees about the string returned at all. Specifically, it is not guaranteed to be a) meaningful, b) unique for different types, c) the same for identical types.

As a quality of implementation issue, you can probably assume that these three conditions hold, but especially for complicated template types I wouldn't be surprised if you could find cases where they were violated in a specific compiler.

The relevant parts of the 98 standard are 5.2.8 and 18.5.1


nope, there are actually different types (in my opinion).

Also typeid().name() is compiler specific.


If the two DLLs are compiled with exactly the same OS, compiler, and compiler options it seems likely that the typeids would be the same.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜