c++ 变量类型判断
PHP中文网
PHP中文网 2017-04-17 15:36:14
0
3
639
  1. 请问下面这个变量m是什么类型?NOTIFICATION 是一个 struct

class EventSensor;

EventSensor<NOTIFICATION> m;
PHP中文网
PHP中文网

认证高级PHP讲师

全部回覆(3)
PHPzhong

如果EventSensor是一個類別模板​​(你給的聲明不是類別模板的聲明)。變數宣告EventSensor<NOTIFICATION> m;會宣告一個以NOTIFICATION為模板參數特化出的類別的實例m,這個類別稱為"EventSensor"(c++標準中便是如此稱呼的)。

也就是說,變數m的型別就是EventSensor<NOTIFICATION>

When template arguments are provided or, for function and class (since C++17) templates only, deduced, they are substituted for the template parameters to temptain a specialization of the template, that; a specific type or a specific function lvalue.

引自cppreference, template

左手右手慢动作

是的, 是class EventSensor內部的變數的型別,只不過在class 定義的時候是泛型,然後用NOTIFICATION實例化的。

伊谢尔伦

m 類型為 EventSensor
是用於class內部的變數的型別,也就是m裡面某個變數的型別。

ArrayList<String> mStrList = new ArrayList<String>();
mStrList.add("string1");
mStrList.add("string2");
String s = mStrList.get(1);

mStrList 的型別為ArrayList

裡面的元素s=mStrList.get(1);的型別為String;

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!