Archived

This topic is now archived and is closed to further replies.

jammyt

How do I do an error of objects

Recommended Posts

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites