typeid

    14热度

    2回答

    可以说我们有一个类层次结构。在底部我们有Base和Derived顶部。 如何确定对象类,即使它被转换为基类指针。 Base* b = new Derived(): typeid(b).name(); // i want this to tell me that this is actually derived not base object 除了手动实现字符串字段或这样的虚拟get函数之外

    5热度

    1回答

    我有B级从A. class A { }; class B : public A { }; 我有三个对象继承的对象类型。 A* a = new A(); A* a2 = new B(); B* b = new B(); 我想如果检查一个是类型A的对象,a2为B型(未A)的目的,以及b是类型B的对象 我试图输入的比较,但它并没有给我正确的答案。 cout << (typeid(

    0热度

    2回答

    包装类所以,我发现这个关于C++的事件相当不错教程: http://www.gamedev.net/page/resources/_/technical/game-programming/effective-event-handling-in-c-r2459 但是:创作者用来TYPE_INFO通过的typeid返回的包装。据我所知,由于type_info的=操作符的不可访问性,这是不可能的。因此,

    1热度

    2回答

    所以即时通讯尝试获取剪贴板的内容在Windows中,因为它可以是任何类型我使用模板来获取它,但是当试图构建时,Visual Studio 2013 RC发送此错误: Error 1 error C2440: 'return' : cannot convert from 'char *' to 'double' Error 2 error C2440: 'return' : cannot conv

    4热度

    2回答

    假设我有一些模板代码执行以下操作: T x = foo(); T y = -x; 现在,如果T是一个非数字型(或不具有执行一元减),编译会因此失败。但如果它是一个unsigned int,unsigned short等,它将成功,并带有警告。所以我想能够做到 T x = foo(); if (/* magic condition */ { T y = -x; } 我可以写表

    1热度

    2回答

    所以我想测试我的物体是魔药还是武器。我如何用typeid(即任何其他方法)做到这一点? 然后我想基于这个条件实例化一个对象。我不能只说T temp,因为它会实例化一个抽象基类(即我的Item类中有一个纯虚函数)。 template <typename T> void List<T>::Load(std::ifstream & file) { //Read the number of elem

    13热度

    2回答

    clang不编译下面的第三个调用typeid(请参阅live example)。但是我在§5.2.8中看不到任何不允许的东西,特别是当我们认为表达式B::f不是多态类类型的glvalue时(参见段落3)。此外,根据该段,表达式B::f是一个未评估的操作数,因此,调用typeid(B::f)应该编译。需要注意的是GCC不编译任何的话费给typeid如下: #include <iostream> #

    3热度

    1回答

    这里的类型名称是我的问题: 我定义了一个新的种类和使用的新类型来声明一个变量: typedef int new_type; new_type value; 我需要以某种方式使用typeid返回new_type作为字符串,但如果我使用: typeid(value) 它将返回int而不是new_type。 有没有办法让new_type返回字符串? 谢谢!

    6热度

    2回答

    我正在上GCC C++编译器代码,输出TYPE_INFO ::名不还原函数typeid的名字: #include <iostream> #include <typeinfo> using namespace std; class shape { protected: int color; public: virtual void draw() =

    2热度

    1回答

    当我运行在Ubuntu这个简单的代码(Ubuntu的13.10,为64位,G ++ 4.8.1): #include <iostream> #include <typeinfo> #include <string> using namespace std; int main(void) { const type_info &ti_trait = typeid(char_tr