Is Reference type in C++ a POD type?

后端 未结 3 503
星月不相逢
星月不相逢 2021-02-08 21:33

Is Reference type in C++ a POD type too? Is int& is a POD type? and what about

struct Q { int& i; }

Anyone can help me?

3条回答
  •  生来不讨喜
    2021-02-08 22:24

    There is a standard way (using C++11) to determine that at compile time.

    #include 
    #include 
    
    struct Q
    {
        int& i;
    };
    
    int main()
    {
        std::cout << std::is_pod::value << "\t";
        std::cout << std::is_pod::value << "\t";
        std::cout << std::is_pod::value << "\n";
    }
    

    Demo: http://ideone.com/PECzfT

    The output will be 1 0 0, so no a reference to int is not POD.

提交回复
热议问题