![]() |
Constructor Syntax help
I've written code to search, add/remove items from a hashtable. My program compiles without errors, but it crashes with an access violation error(msvcr80d.dll!strcat...). I haven't found any solutions to that particular message, so I've decided to start with the constructors. I'd appreciate any suggestions. I cannot let this code defeat me! My professor tried to help me and finally suggested I see tutors. The tutor tried to help me for several hours and finally suggested the internet.
From stock.h: :
class stockFrom stock.cpp: :
stock::stock(char const * const symbol, char const * const name, int sharePrice, date priceDate): |
Re: Constructor Syntax help
In the code you've given, your copy constructor and assignment operators are among the obvious candidate culprits.
The assignment operator will need to be something like this; :
stock &stock::operator=(const stock& s): :
stock::stock(const stock& s):The default constructor (the one with no arguments) is also a problem, as the non-static members are uninitialised, and you are using them to initialise themselves. That is formally undefined behaviour. If you really need such a constructor, provide more sensible default values. It would probably be a good idea to use a std::string, rather than char * members, but that won't help you understand the problem you're having. |
Re: Constructor Syntax help
What grumpy said (but with an extra '['). Also, is there any point to that last constructor which takes a pointer?
|
Re: Constructor Syntax help
Oh, bugger! One time when I wish to edit my post to make the content clearer, and can't.
|
Re: Constructor Syntax help
Thanks. After I corrected my constructors and copy consturctors, I was able to see all of my "other" compile errors. One of my copy constructor errors was that I had two copies.
Good times. |
| All times are GMT -5. The time now is 3:34 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC