--- title: "__if_exists Statement | Microsoft Docs" ms.custom: "" ms.date: "11/04/2016" ms.reviewer: "" ms.suite: "" ms.technology: - "cpp-language" ms.tgt_pltfrm: "" ms.topic: "language-reference" f1_keywords: - "__if_exists_cpp" - "__if_exists" dev_langs: - "C++" helpviewer_keywords: - "identifiers, testing for existence" - "symbols, testing for existence" - "__if_exists keyword [C++]" ms.assetid: d3eb34b6-f3a9-4063-a286-b62a28c0c7fa caps.latest.revision: 10 author: "mikeblome" ms.author: "mblome" manager: "ghogen" translation.priority.ht: - "cs-cz" - "de-de" - "es-es" - "fr-fr" - "it-it" - "ja-jp" - "ko-kr" - "pl-pl" - "pt-br" - "ru-ru" - "tr-tr" - "zh-cn" - "zh-tw" --- # __if_exists Statement The `__if_exists` statement tests whether the specified identifier exists. If the identifier exists, the specified statement block is executed. ## Syntax ``` __if_exists ( identifier ) {  statements }; ``` #### Parameters |Parameter|Description| |---------------|-----------------| |`identifier`|The identifier whose existence you want to test.| |`statements`|One or more statements to execute if `identifier` exists.| ## Remarks > [!CAUTION] > To achieve the most reliable results, use the `__if_exists` statement under the following constraints. - Apply the `__if_exists` statement to only simple types, not templates. - Apply the `__if_exists` statement to identifiers both inside or outside a class. Do not apply the `__if_exists` statement to local variables. - Use the `__if_exists` statement only in the body of a function. Outside of the body of a function, the `__if_exists` statement can test only fully defined types. - When you test for overloaded functions, you cannot test for a specific form of the overload. The complement to the `__if_exists` statement is the [__if_not_exists](../cpp/if-not-exists-statement.md) statement. ## Example Notice that this example uses templates, which is not advised. ``` // the__if_exists_statement.cpp // compile with: /EHsc #include template class X : public T { public: void Dump() { std::cout << "In X::Dump()" << std::endl; __if_exists(T::Dump) { T::Dump(); } __if_not_exists(T::Dump) { std::cout << "T::Dump does not exist" << std::endl; } } }; class A { public: void Dump() { std::cout << "In A::Dump()" << std::endl; } }; class B {}; bool g_bFlag = true; class C { public: void f(int); void f(double); }; int main() { X x1; X x2; x1.Dump(); x2.Dump(); __if_exists(::g_bFlag) { std::cout << "g_bFlag = " << g_bFlag << std::endl; } __if_exists(C::f) { std::cout << "C::f exists" << std::endl; } return 0; } ``` ## Output ``` In X::Dump() In A::Dump() In X::Dump() T::Dump does not exist g_bFlag = 1 C::f exists ``` ## See Also [Selection Statements](../cpp/selection-statements-cpp.md) [Keywords](../cpp/keywords-cpp.md) [__if_not_exists Statement](../cpp/if-not-exists-statement.md)