views:

58

answers:

3

Hello, I have two dlls which both declare a templated type, let's call A. 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

A: 

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

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

nob
A: 

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.

Mark B
+1  A: 

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

KeithB
thank you, it is just the worst case I was afraid of!
rob