简体   繁体   English

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

[英]'new char[]' does not work, but it should

I had the code, that returned char* If a write in cpp: 我有代码,该代码返回char *如果在cpp中写入:

char* test_char = new char[size];

all is good, but if i write in header: 一切都很好,但是如果我在标题中写:

char* test_char;

and in cpp: 在cpp中:

test_char = new char[size];

the program compiles but does not run. 该程序可以编译但无法运行。

What am I doing wrong? 我究竟做错了什么?

char = new char[size]; char =新的char [size];

You probably want 你可能想要

test_char = new char[size];
char = new char[size];

This should not even compile. 这甚至不应该编译。 You are missing a variable name: 您缺少变量名:

test_char = new char[size];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM