This code gives errors
incomplete type is not allowed
too many initializer values
string *ReturnTwoStringsInArray()
{
return new string[]{"return1", "return2"};
}
This one works:
string *ReturnTwoStringsInArray()
{
return new string[2]{"return1", "return2"};
}
And so does this one:
string arr[]{"return1","return"};
Shouldn't we be able to call new
with no parameters in []
if the compiler can determine the needed size from the initializer list?
An incomplete class declaration is a class declaration that does not define any class members. You cannot declare any objects of the class type or refer to the members of a class until the declaration is complete.
but no definition for struct foo itself, gdb will say: (gdb) ptype foo $1 = <incomplete type> “Incomplete type” is C terminology for data types that are not completely specified.
In C++ compiler support we can see that the defect report P1009R2
:Array size deduction in new-expressions has not been adopted by all compiler vendors yet.
P1009R2
says: "The effect of the wording changes should be applied in implementations of all previous versions of C++ where they apply."
clang++
supports it from version 9 in C++11 mode and later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With