Arrays of classes
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?
Dont know what the errors are from but wouldnt it be better to do like...
button.new()
button.load()
button.quit()?
button.new()
button.load()
button.quit()?
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?
How do i make an array of a class?
See if this works:
Button buttons[3] = {Button(constructor info a), Button(constructor info b), Button(constructor info c)};
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement