C++编程中__if_exists与__if_not_exists语句的用法

2020-01-06 14:20:12于海丽

Output


In X<T>::Dump()
In A::Dump()
In X<T>::Dump()
T::Dump does not exist
g_bFlag = 1
C::f exists

 

__if_not_exists 语句
__if_not_exists 语句测试指定的标识符是否存在。如果该标识符不存在,则执行指定的语句块。
语法


__if_not_exists ( identifier ) { 
statements
};

参数

参数 说明
identifier 要测试其存在性的标识符。
statements identifier 不存在时要执行的一个或多个语句。

 

备注
若要实现最可靠的结果,请在以下约束条件下使用 __if_not_exists 语句。
只将 __if_not_exists 语句应用于简单类型而不是模板。
将 __if_not_exists 语句应用于类的内部或外部的标识符。不要将 __if_not_exists 语句应用于局部变量。
仅在函数的主体中使用 __if_not_exists 语句。在函数主体的外部,__if_not_exists 语句仅能测试完全定义的类型。
在测试重载函数时,不能测试特定形式的重载。
__if_not_exists 语句的补集为 __if_exists 语句。



注:相关教程知识阅读请移步到C++教程频道。