C 通過typeinfo獲取物件型別 cpp

2021-07-25 20:29:25 字數 1069 閱讀 2358

/*c++獲取物件型別

* 可用typeid(object_name).name()函式,該函式在標頭檔案 中 */

#include

#include

using namespace std;

struct student ;

int main() ;

char b[3] = ;

student  x[6];

double* p1 = null;

int* p2 = null;

string s;

cout << "name = " << typeid(a1).name() << endl;

cout << "name = " << typeid(a2).name() << endl;

cout << "name = " << typeid(b).name() << endl;

cout << "name = " << typeid(x).name() << endl;

cout << "name = " << typeid(p1).name() << endl;

cout << "name = " << typeid(p2).name() << endl;

cout << "name = " << typeid(s).name() << endl; }

/*a1 : i          // 表示 a1 是 int 型別

a2 : a5_i       // 表示 a2 是 int 型 array(陣列),陣列有5個元素   

b  : a3_c       // 表示 b 是 char 型 array(陣列),陣列有3個元素

x  : 6_7student // 表示 x 是student型別陣列,型別名字有7個字元 ,陣列有6個元素

p1 : pd         //表示p1是double 型別point(指標)型別

p2 : pi         //表示p2是int型別指標

s  : nst7__cxx1112basic_stringicst11char_traitsicesaiceee

//這個鬼我也不懂 */

通過反射獲取,修改物件變數

最近工作不是太忙,就把自己的筆記整理出來,分享一下。這個是通過反射獲取修改物件變數的,有需要的可以看看,大神繞道 反射遍歷修改變數 field fidles map.get object.getmsgid getclass getdeclaredfields field fidlesother ob...

MVC 通過物件獲取整個表單內容

在mvc的controller 控制器 裡面定義相同的方法時,我們需要解決過載問題 解決方案一 在引數中定義乙個formcollection型別,解決問題 解決方案二 利用從前台獲取資料解決問題 public actionresult editor string username mvc在呼叫act...

MVC 通過物件獲取整個表單內容

在mvc的controller 控制器 裡面定義相同的方法時,我們需要解決過載問題 解決方案一 在引數中定義乙個formcollection型別,解決問題 解決方案二 利用從前台獲取資料解決問題 public actionresult editor string username mvc在呼叫act...