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

class EventSensor;

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

认证高级PHP讲师

全員に返信(3)
PHPzhong

如果EventSensor是一个类模板(你给出的声明不是类模板的声明)。变量声明EventSensor<NOTIFICATION> m;会声明一个以NOTIFICATION为模板参数特化出的类的实例m,这个类称作"EventSensor<NOTIFICATION>"(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 obtain a specialization of the template, that is, a specific type or a specific function lvalue.

引自cppreference, template

いいねを押す +0
左手右手慢动作

是的,<NOTIFICATION> 是class EventSensor内部的变量的类型,只不过在class 定义的时候是泛型,然后用NOTIFICATION实例化的。

いいねを押す +0
伊谢尔伦

m 类型为 EventSensor
<NOTIFICATION> 是用于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;

いいねを押す +0
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!