Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How initialize array of classes?

Tags:

People also ask

How do you create an array of classes in Java?

Creating an Array Of Objects In Java – We use the Class_Name followed by a square bracket [] then object reference name to create an Array of Objects. Class_Name[ ] objectArrayReference; Alternatively, we can also declare an Array of Objects as : Class_Name objectArrayReference[ ];

What is the correct way to initialize an array?

The initializer for an array is a comma-separated list of constant expressions enclosed in braces ( { } ). The initializer is preceded by an equal sign ( = ). You do not need to initialize all elements in an array.


I have this class constructor:

Pairs (int Pos, char *Pre, char *Post, bool Attach = true);

How can I initialize array of Pairs classes? I tried:

Pairs Holder[3] =
{
    {Input.find("as"), "Pre", "Post"},
    {Input.find("as"), "Pre", "Post"},
    {Input.find("as"), "Pre", "Post"}
};

Apparently it's not working, I also tried to use () brackets instead of {} but compiler keeps moaning all the time. Sorry if it is lame question, I googled quite hard but wasn't able to find answer :/