'new char []'不起作用,但它应该

-1 c++ memory pointers return object

我有代码,返回char*如果在cpp中写:

char* test_char = new char[size];
Run Code Online (Sandbox Code Playgroud)

一切都很好,但如果我写在标题:

char* test_char;
Run Code Online (Sandbox Code Playgroud)

在cpp中:

test_char = new char[size];
Run Code Online (Sandbox Code Playgroud)

程序编译但不运行.

我究竟做错了什么?

Nem*_*vic 5

char = new char [size];

你可能想要

test_char = new char[size];
Run Code Online (Sandbox Code Playgroud)