Ex9_03, page 483 & '571974 Code from the book'
Odd problem here: I had an error so I compared with the relevant files in the source code (i.e. '571974 Code from the book').
Problem exists around CandBox.h
In the book, page 483, we have:
---
...
cout << endl <<"CCandyBox constructor2 called";
m_Contents = new char [strlen(str) + 1];
strcpy_s(m_Contents, strlen(str)+1, str);
}
//constructor to set contents
//calls default CBox constructor automatically
CCandyBox(char* str ="Candy")
{
cout<< endl<< "CCandyBox constructor1 called";
m_Contents = new char [strlen(str)+1];
strcpy_s(m_Contents, strlen(str)+1, str);
...
-------------------
In the source code ('571974 Code from the book'), two lines are changed:
Both entries of: strcpy_s(m_Contents, strlen(str)+1, str);
have been changed to:
strcpy_s(m_Contents, strlen(m_Contents), str);
strlen(m_Contents)... causes the executable to crash, although I have not worked out why. m_Contents and str are the same.
The crash seems to occur when it comes to displaying '<< sizeof myBox' in EX9_03.cpp
|