c++ - Unhandled Exception Error, Memory Violation -


My program crashes, as if a new MyString object is created.

When the string array [0] is set on a null care in the constructor, I get a memory access violation. any idea?

Here is the constructor

  MyString :: MyString () {stringSize = 0; String cap = 16; Stringarrow [string cap + 1]; Stringer [0] = '\ 0'; }   

Here classes are private members

  char * stringArray; Int stringCap; Int stringSize;   

This is the main place where the main.cpp is built in

  MyString s1;    

This row does not allocate memory:

  Stringarrow [string cap + 1];   

You need to change it with:

  stringArray = new char [stringCap + 1];   

Do not forget to erase memory.

The addition of 3 rules applies here because you have an object-owned raw memory.

Alternatively if you don; Do not want dynamic alignment but rather fixed size string after that you can change the declaration of your members:

  four string array [& lt; FixedSyzairHouse & gt; ];    

Comments