有什么类似于C ++中的typeof?

时间:2013-03-13 21:13:11

标签: c++

我正在尝试创建一个构造函数,说明它存储的对象类型。有没有简单的方法来实现这一目标?我在看decltype。

template <typename T>
MyVector<T>::MyVector(int setCap)
{
    m_ptr = new T[setCap];
    m_size = 0;
    m_capacity = setCap;
    string typeSet = decltype(T);
    cout << "New MyVector of type " << typeSet << " created\n";
}

1 个答案:

答案 0 :(得分:2)

C ++有typeid

#include <typeinfo>

std::cout << "The type is " << typeid(T).name();
相关问题