Thread: Arrays and Constructors

  1. #1
    Registered User
    Join Date
    May 2004

    Arrays and Constructors

    Hi everyone. I have this class...

    class ApplicationType
       vUIButton Buttons[5];
    and I need the constructor of this ApplicationType to set up all my buttons. The buttons' constructors look like this:

    vUIButton( char* Text, RectangleType* Area )
    (So normally I would make a button by saying "vUIButton ExitButton( "Exit", NULL );".)

    How do I do this with an array? I want the buttons to be like this:
    1. "New", NULL
    2. "Load", NULL
    3. "Options", NULL
    4. "Credits", NULL
    5. "Exit", NULL

    I know that i could do it like this...

    vUIButton Buttons =
       vUIButton( "New", NULL ),
       vUIButton( "Load", NULL ),
       vUIButton( "Options", NULL ),
       vUIButton( "Credits", NULL ),
       vUIButton( "Exit", NULL )
    ...but this won't work in the constructor.

    How do I use an array's objects' constructors in the constructor of the class that contains them? (Wow, that was a weird sentence...)

    Thank you very much for your time. It is greatly appreciated!

  2. #2
    Registered User
    Join Date
    Jan 2005
    You don't. You can just skip the use of the array's objects' constructor and use member functions or whatever to set the data instead. Or you can use a vector and push_back objects which will allow you to use the constructor.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Constructors for creating 2d arrays
    By Welshy in forum C++ Programming
    Replies: 5
    Last Post: 06-29-2005, 03:50 PM
  2. dynamic arrays in class's???
    By j0hnb in forum C++ Programming
    Replies: 2
    Last Post: 12-05-2004, 01:10 PM
  3. constructors, arrays, and new
    By Thantos in forum C++ Programming
    Replies: 6
    Last Post: 05-30-2004, 06:21 PM
  4. my vector class..easy dynamic arrays
    By nextus in forum C++ Programming
    Replies: 5
    Last Post: 02-03-2003, 10:14 AM
  5. constructors in arrays
    By DavidP in forum A Brief History of
    Replies: 3
    Last Post: 12-07-2001, 03:17 AM