📜  C++中的std :: add_volatile与示例

📅  最后修改于: 2021-05-30 06:52:19             🧑  作者: Mango

< type_traits >头文件中提供了C++ STL的std :: add_volatile模板。 C++ STL的std :: add_volatile模板用于获取具有易失性限定的T类型。函数std :: is_volatile用于检查类型T是否为volatile限定。

头文件:

#include

模板类别:

template < class T >
struct add_volatile;

句法:

std::add_volatile::value

参数:模板std :: add_volatile接受单个参数T(Trait类) ,该参数用于获取具有volatile限定的T类型。

下面是演示C++中std :: add_volatile:的程序:

程序:

// C++ program to illustrate
// std::add_volatile
#include 
#include 
using namespace std;
  
// Driver Code
int main()
{
  
    // Declare variable of type
    // volatile (int, const int, const int*,
    // int * const and const int&)
    typedef add_volatile::type A;
    typedef add_volatile::type B;
    typedef add_volatile::type C;
    typedef add_volatile::type D;
    typedef add_volatile::type E;
  
    cout << boolalpha;
  
    // Checking the volatileness of
    // the above declared variable
    cout << "checking volatileness:"
         << endl;
  
    cout << "A: "
         << is_volatile::value
         << endl;
  
    cout << "B: "
         << is_volatile::value
         << endl;
  
    cout << "C: "
         << is_volatile::value
         << endl;
  
    cout << "D: "
         << is_volatile::value
         << endl;
  
    cout << "E: "
         << is_volatile::value
         << endl;
  
    return 0;
}
输出:
checking volatileness:
A: true
B: true
C: true
D: true
E: false

参考: http : //www.cplusplus.com/reference/type_traits/add_volatile/

要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”