gpt4 book ai didi

c++ - Constexpr默认功能

转载 作者:行者123 更新时间:2023-12-02 09:52:52 25 4
gpt4 key购买 nike

可以是constexpr的默认函数是隐式constexpr吗?

class c
{
public:
constexpr /*<- necessary?*/ c() = default;
constexpr /*<- necessary?*/ c(c const&) = default;
constexpr /*<- necessary?*/ c(c &&) = default;
constexpr /*<- necessary?*/ c& operator =(c const&) = default;
constexpr /*<- necessary?*/ c& operator =(c &&) = default;
~c() = default;

private:
int x = 0;
};
那么其他限定词,例如 noexcept呢?

最佳答案

是的,如果默认特殊成员满足constexpr成员的要求,则为constexpr。特别是,有关默认构造函数,请参见11.4.4.1/4:

A default constructor that is defaulted and not defined as deleted is implicitly defined... The implicitly-defined default constructor performs the set of initializations of the class that would be performed by a user-written default constructor for that class with no ctor-initializer and an empty compound-statement. ... If that user-written default constructor would satisfy the requirements of a constexpr constructor ([dcl.constexpr]), the implicitly-defined default constructor is constexpr. Before the defaulted default constructor for a class is implicitly defined, all the non-user-provided default constructors for its base classes and its non-static data members are implicitly defined. ...


其他特殊成员也有类似的措辞。

关于c++ - Constexpr默认功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62924967/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com