The problem is that the expression test.size()
is equivalent to this->test.size()
but the this
object is more of a run-time construct. In particular, in standard C++ the size of an array must be a compile-time constant(aka constant expression) which the expression this->test.size()
is not. From expr.const#2:
An expression e
is a core constant expression unless the evaluation of e
, following the rules of the abstract machine, would evaluate one of the following expressions:
this
, except in a constexpr function or a constexpr constructor that is being evaluated as part of e
;
Now in your example, this
appears inside the member function method
but the member function method
is neither constexpr nor it is being evaluated as part of the expression this->test.size()
.
Therefore this->test.size()
cannot be used to specify the size of the array since that expression is not a compile-time constant.