开发者

How initialize array of classes?

开发者 https://www.devze.com 2023-01-02 05:33 出处:网络
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:

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 tim开发者_StackOverflowe. Sorry if it is lame question, I googled quite hard but wasn't able to find answer :/


Call the constructor explicitly:

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


Call the constructor:

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

This is similar to saying

Holder[0] = Pairs(Input.find("as"), "Pre", "Post");
Holder[1] = Pairs(Input.find("as"), "Pre", "Post");
Holder[2] = Pairs(Input.find("as"), "Pre", "Post");

A full-fledged class can be found here.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号