[英]Qualifiers for a variable in C++
How do I know if qualifiers like const
etc are associated with the passed arguments to a function?我如何知道
const
等限定符是否与传递给 function 的 arguments 相关联?
eg例如
template<class T>
void callback(T & data)
{
body of function
}
How do I know if the data is const
etc?我如何知道数据是否为
const
等?
You can test whether a type (including a template type argument) is const qualified using a standard type trait:您可以使用标准类型特征测试类型(包括模板类型参数)是否为 const 限定:
bool is_const = std::is_const_v<T>;
If T
is const qualified, then and only then is T&
a reference to const.如果
T
是 const 限定的,那么并且只有T&
是对 const 的引用。
Whether or not the referred object is const is something that cannot be inspected.提到的 object 是否为 const 是无法检查的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.