How can I create new char[]
in a function or constructor? When I need the array size will be as I got by parameter?
The code:
MyString::MyString (int length=10)
{
char myCharArray[length];
}
The errors I get:
expected constant expression
cannot allocate an array of constant size 0
'myCharArray' : unknown size
I already tried the following:
- Give an initial value in the function.
- Adding
const
to theint
value.
Note: in this task I can't use std::string
, although I wish so.