typeid结果跨越不同的dll [英] typeid result across different dll's

查看:267
本文介绍了typeid结果跨越不同的dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个dll,都声明一个模板类型,让我们调用A.
如果A的声明是充分复杂,它发生
typeid(A).name()的结果是

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.

示例:

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();
    }

例如name1可能是这样: etc
而name2可以是A TEMPLATE_LIST_OF_A等。

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

这实际上对我来说很有意义,但是有一种方法,条件是所使用的
名称是samem以保证name1 == name2?

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 ?

感谢,
rob

thanks, rob

推荐答案

不仅没有办法保证 typeid()。name()在不同的DLL中,标准几乎不能保证返回的字符串。具体来说,不能保证a)有意义,b)对于不同类型是唯一的,c)对于相同类型是相同的。

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.

作为一个实现质量问题,你可以假设这三个条件成立,但是对于复杂的模板类型,我不会感到惊讶,如果你可以找到case

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.

98标准的相关部分是5.2.8和18.5.1

The relevant parts of the 98 standard are 5.2.8 and 18.5.1

这篇关于typeid结果跨越不同的dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆