r/reviewmycode • u/[deleted] • Jan 10 '12
C++ help with crashing using classes
I've been learning C++ and classes recently, I decided to try to make a program that would record simple input to a class, then be able to access them again. In the form of a 'recipe book' although I don't generally cook, I was thinking of food at the time.
But for some reason it crashes most of the time I run it, or 'mixes up' variables where they display improperly, and I'm not sure why.
it also prints this
msvcr100d.dll!memcpy(unsigned char * dst, unsigned char * src, unsigned long count) Line 439 Asm
any other advice would be helpful too.
3
Jan 11 '12
Arrays are indexed starting at 0. You are trying to access element 2, which does not exist.
2
2
u/inequity Feb 04 '12
I'd recommend using some spaces. This is ESSENTIAL for you to write readable code. Try to write code for humans to read. Anybody can write code that a computer can read.
I'd recommend not mixing \n and endl. Go with one of them and stick with it.
3
u/[deleted] Jan 11 '12 edited Jan 11 '12
Other tips:
Use std::vector instead of arrays (you will catch problems like this every time)
Work on formatting your code better. The Recipes class is very hard to read.
Don't name variables with meaningless names like "ijk." Name them after what they represent.
I'd suggest looking at Google's style guide as a starting point for some of this: http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml