I'm trying to allocate a dynamic array and initialize it with the content "Hello World". The code is as below.
char *text = new char[]{"Hello World"};
This works perfectly in Visual C++, but throws the below errors in gcc.
test.cc:3:24: error: expected primary-expression before ‘]’ token
char *text = new char[]{"Hello World"};
^
test.cc:3:39: error: invalid conversion from ‘const char*’ to ‘char’ [-fpermissive]
char *text = new char[]{"Hello World"};
^
Need help with the following questions.
- Is there any known defect in gcc?
- Shouldn't it work as per the standard?
- Is Visual C++ Compiler going out of its way to support this?
- Should this be done differently in gcc?