|
Hi,
You don't need to return anything from your setters. Make them void like this:
void setName(const string& name){m_name = name;}
void setGender(const string& gender){m_gender = gender;}
void setWeight(const string& weight){m_weight = weight;}
Try this and if you still get error messages, please post the exact message here.
Nuri Ismail
|
|
|
|
|
this doesn't help, I get
Unhandled exception at 0x1026edac (msvcr90d.dll) in Zoo.exe: 0xC0000005: Access violation writing location 0xcdcdcdcd
|
|
|
|
|
Sivyo wrote: Unhandled exception at 0x1026edac (msvcr90d.dll) in Zoo.exe: 0xC0000005: Access violation writing location 0xcdcdcdcd
Most likely, you are either accessing a memory location that is not been allocated or has been freed already.
I've tried the code from your modified post and it works fine.
Maybe you should go step by step through your main method and track your heap objects.
You should also use the call stack window in order to see the exact position of the crash in your code.
Nuri Ismail
|
|
|
|
|
I don't actually know how to use the call stack window. I will google it see if that will help.
I did debug it and create break points and it always crashes right after set weight.
I checked out the watch. and everything goes where it is supossed to but then it just crashes right after everything is set.
I commented out set weight and it seems that is the problem, it doesn't crash if I take it out
|
|
|
|
|
Sivyo wrote: I commented out set weight and it seems that is the problem, it doesn't crash if I take it out
Don't be so sure. You may have just moved the problem to another, less-sensitive location.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
well, apparently something was wrong with that computer. I was working with it at school and now that I am home, the program works fine.
Makes me feel really stupid.... worked 4 hours on that thing and the problem was with the computer. i didn't get anything done....
|
|
|
|
|
Post ere more info about the unhandled exception (the debugger helps a lot, see for instance the call stack window).
BTW you didn't post the Goldfish class code.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
the debuggers shows me this window and shows me where it stops...
LeadUp1:
and edx,ecx ;U - trailing byte count
mov al,[esi] ;V - get first byte from source
it stops here
-> mov [edi],al ;U - write second byte to destination
mov al,[esi+1] ;V - get second byte from source
mov [edi+1],al ;U - write second byte to destination
mov al,[esi+2] ;V - get third byte from source
it compiles it fine, but once it executes it I get the
Unhandled exception at 0x1026edac (msvcr90d.dll) in Zoo.exe: 0xC0000005: Access violation writing location 0xcdcdcdcd
|
|
|
|
|
|
I modified my origional post. Its all up there
|
|
|
|
|
Your code is working fine on my system, however I had to do the following modifications, in order to compile it:
Commented out few lines (I haven't all your animal classes ), hence
int main(int argc,char* argv[])
{
Animals *ourAnimals[6];
Animals *goldfish = new Goldfish();
ourAnimals[0]=goldfish;
string name, gender, weight;
name = "the Goldfish";
gender = "Female";
weight = "One Ounce";
goldfish -> setName(name);
goldfish -> setGender(gender);
goldfish -> setWeight(weight);
}
Added the constructor and destructor for the Animals (misname? Wouldn't be better 'Animal'?) class:
class Animals
{
public:
Animals(void){};
virtual ~Animals(void){};
Again and again: use the debugger and have a look at the call stack window.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
noticed (with some help from inside sources) that in the problem is with the compiler for some odd reason it doesn't like creating a 3rd variable of string in Animals.
I moved weight be to be first and name was last (3rd) then it showed Bad ptr message in the debugger.
its a very strange error....
|
|
|
|
|
Sivyo wrote: In main() you have
goldfish -> setName(name);
but in class Animals you have
string setName(string &name){return m_name = name;}
I think your setName() definition should read:
string setName(string name){return m_name = name;}
Also as mentioned previously there is little to be gained in the setXXX() functions in returning the parameter values. Using void return types is better as:
void setName(string name)
{
m_name = name;
}
|
|
|
|
|
I think there's nothing wrong in his method signature.
Why should he pass the string by value?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Yes, the old brain only working on one cylinder...confusing string with char*.
|
|
|
|
|
noticed when moving around the protected names...
protected:
string m_weight;
string m_name;
string m_gender;
the problem moves to gender. ect...
very very strange
|
|
|
|
|
Even stranger ... I have copied your code, compiled and run it and it works perfectly! May I suggest the extracts you have posted lack some information relevant to the problem.
|
|
|
|
|
|
What do you mean by lock?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
Send the EM_SETREADONLY [^] message to the edit box.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
How to create an HBITMAP from a window's HDC?
|
|
|
|
|
CreateCompatibleBitmap [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
NO, I want that it is like the LoadBitmap function.
|
|
|
|
|
vcguileaner wrote: NO, I want that it is like the LoadBitmap function.
What do you mean? Do you want to copy the window client area to a bitmap?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|