gpt4 book ai didi

c++ - gcc 4.7 中的错误?与否,我不确定所以我在这里问

转载 作者:行者123 更新时间:2023-11-30 02:04:13 24 4
gpt4 key购买 nike

在此代码段中:

template<class T, int Min, int Max>
class Range
{
const T min_ = Min; // works without const

T max_ = Max;

};

我遇到了错误

non static const member in class without ctor

但是如果我在类中初始化它,这就无关紧要了。应该将其记录为错误吗?

最佳答案

是的。隐式构造函数包含这些初始值设定项,因此不会发生错误。 §12.1/6:

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 (12.6.2) and an empty compound-statement. If that user-written default constructor would be ill-formed, the program is ill-formed.

和 12.6.2/8:

In a non-delegating constructor, if a given non-static data member or base class is not designated by a mem-initializer-id (including the case where there is no mem-initializer-list because the constructor has no ctor-initializer) and the entity is not a virtual base class of an abstract class (10.4), then

— if the entity is a non-static data member that has a brace-or-equal-initializer, the entity is initialized as specified in 8.5;

关于c++ - gcc 4.7 中的错误?与否,我不确定所以我在这里问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10917875/

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