How do I do an error of objects

Started by
3 comments, last by jammyt 20 years, 8 months ago
I''m writing a version of the classic Chuckie Egg but can''t get my objects to work. I''ve not programmed in C++ since uni 3 years ago and I can''t remember how to do a lot of things. I''ve tried looking this up on the net but to no avail. I''ve got a class called Goose. When I create 1 goose it is fine but I want to create an array of geese so I can have multiple baddies. I''ve got a global variable: Goose *geese[2]; and then in my main code: geese[0] = new Goose(); geese[1] = new Goose(); Does this look correct? I''ve a bit confused because my application is now crashes strangely and I''m thinking that the memory may not have been allocated correctly or something. As I said if I create 1 goose with the following code it works fine: Goose goose1; goose1 = Goose(); Any ideas to what I''m doing wrong with the array? Jam
Advertisement
I apologise for the double post, my computer did something wierd when I hit submit and now I can''t seem to delete it. Please could someone remove this double post.
how about trying new Goose without the parenthesis unless you''re planning on intializing it with something.




--{You fight like a dairy farmer!}

--{You fight like a dairy farmer!}

quote:how about trying new Goose without the parenthesis unless you''re planning on intializing it with something.


That does exactly the same thing when there are no parameters to pass to the constructor. Your code looks correct. Your error is somewhere else. Have you run it with the debugger to see where exactly the crash occurs?
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
Goose geese[2] <-- this will create an array of 2 Gooses. geese[0] and geese[1].

This topic is closed to new replies.

Advertisement