URL*_*L87 3 c++ templates typeid
有 -
C_Type.h
#ifndef C_TYPE_H
#define C_TYPE_H
template <class T>
class C_Type {
public:
T m_val;
// implementation ...
};
#endif
Run Code Online (Sandbox Code Playgroud)
一个程序 -
#include <iostream>
#include <typeinfo>
#include "C_Type.h"
using namespace std ;
int main () {
C_Type<int> a ;
cout <<typeid(a.m_val).name()<<endl;
}
Run Code Online (Sandbox Code Playgroud)
我试图提取int哪个C_Type<int>组成,上面的程序只给出了输出 - i.
编辑:
是否可以获得类型(即int或i)而不考虑类成员(即m_val)?