Jump to content
  • Advertisement

Archived

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

jammyt

How do I do an error of objects

This topic is 5523 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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.

Share this post


Link to post
Share on other sites
how about trying new Goose without the parenthesis unless you''re planning on intializing it with something.





--{You fight like a dairy farmer!}

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
Guest Anonymous Poster
Goose geese[2] <-- this will create an array of 2 Gooses. geese[0] and geese[1].

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!