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

class EventSensor;

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

认证高级PHP讲师

reply all(3)
PHPzhong

If EventSensor is a class template (the declaration you gave is not a declaration of a class template). The variable declaration EventSensor<NOTIFICATION> m; will declare an instance m of a class specialized with NOTIFICATION as the template parameter. This class is called "EventSensor<NOTIFICATION>" (this is how it is called in the C++ standard).

In other words, the type of variable m is 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.

Quoted from cppreference, template

左手右手慢动作

Yes, <NOTIFICATION> is the type of variable inside class EventSensor, but it is generic when the class is defined and then instantiated with NOTIFICATION.

伊谢尔伦

m is of type EventSensor
<NOTIFICATION> which is the type of variables used inside the class, that is, the type of a variable in m.
as

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

mStrList is of type ArrayList

The type of element s=mStrList.get(1); in

is String;

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template