Похожие чаты

Hey everyone, after using delete[] to free memory of dynamic

array i've got this error. what im doing wrong?

13 ответов

9 просмотров

can you copypaste your code somewhere (pastebin, hastebin), it is very small on this screenshot to read it from phone

probably calling delete[] on an already deleted array.

by the way, why don't you use std::string?

German- Автор вопроса
Pavel
can you copypaste your code somewhere (pastebin, h...

https://pastebin.com/FX7n5BJN https://pastebin.com/FSrBd3Z2 https://pastebin.com/D3VSaPKB

German- Автор вопроса
German
https://pastebin.com/FX7n5BJN https://pastebin.co...

here are 3 file of my code. 2 for class and 1 for main

German
https://pastebin.com/FX7n5BJN https://pastebin.co...

Your string created on stack as array of char (name1 in main()) then you call delete on it in the destructor of Player. And that because of this code in the constructor char* buffer = name; int name_size = strlen(buffer); name = new char [name_size + 1]; this->name = buffer; this->symbol = symbol; You assign name (input parameter) to buffer and then assign buffer to this->name.

German- Автор вопроса
Pavel
by the way, why don't you use std::string?

i cannot use std::string on this project (course rules...)

German
i cannot use std::string on this project (course r...

Ah, that's bad. Because in C++ we don't write code like this usually, it's very error prone (and extra verbose).

German- Автор вопроса
Pavel
Your string created on stack as array of char (nam...

Which way is good to fix it without using std::string?

German
i cannot use std::string on this project (course r...

what about smart pointers like std::shared_ptr<std::array<char>> ?

German
Which way is good to fix it without using std::str...

If feels like the code in the constructor is not entirely correct, you probably wanted to assign result of new directly to this->name? Also, pass name as const char* not char*, then compiler will not let you modify it accidentally

German
Which way is good to fix it without using std::str...

also, it seems like you need to do strcpy there, not assign string one to another

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта