C++ constexpr类

1 constexpr类.cpp

#include<iostream>

using namespace std;

//constexpr 类是指该类的构造函数被constexpr修饰后,其传递的参数不能是变量,只能是常量(只读变量,字面值)
class A{
    int a,b;
    public:
    A(){}
    constexpr A(int ra,int rb):a(ra),b(rb){}
    ~A(){}
};

int main()
{
    int m=10,n=9;
//err:  A a(m,n);
    A b(10,9);

}

原文地址:https://www.cnblogs.com/Sico2Sico/p/5384233.html