• Advertisement
Sign in to follow this  

Arrays of classes

This topic is 4500 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

So i've posted some pretty beginner questions but this is the last one i swear. I've been trying to perfect my button class (i've created my own cuz Allegro's is ugly as sin) and i need three buttons created from this class, so instead of making them all seperate like this: Button button_new(constructor info); Button button_load(constructor info); Button button_quit(constructor info); i wanted to do it like this : Button buttons[3] = {(constructor info a), (constructor info b), (constructor info c)}; but when i do that i get the errors : conversion from `int' to non-scalar type `Button' requested for every part of the array (so 3 errors). How do i initialize a class as an array that has a constructor?

Share this post


Link to post
Share on other sites
Advertisement
I dont want to do it that way because if i do it in an array i can write the program using loops for the classes. so i could check each button's state and draw each button in a single loop consisting of about 6 lines, instead of 3 lines to each button creating a chunk of code about 12 lines long.

How do i make an array of a class?

Share this post


Link to post
Share on other sites
Quote:
Original post by Roboguy
See if this works:

Button buttons[3] = {Button(constructor info a), Button(constructor info b), Button(constructor info c)};


i didn't know you could do that! i always thought the default constructor would get called first so you would need a set function to do that. learn something new every day.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement