Objects with arguments and array

前端 未结 4 503
轮回少年
轮回少年 2021-01-06 06:36

Is there a way in C++ where an objects has argument added upon it, with an array such as:

int x = 1;
int y = 2;

Object myObject( x, y )[5]; // does not work         


        
4条回答
  •  隐瞒了意图╮
    2021-01-06 07:15

    You haven't mentioned which language yet, but in C# 3.0 you can get close with collection initializers:

    var myObject = new List() {
        new Object(x,y),
        new Object(x,y),
        new Object(x,y),
        new Object(x,y),
        new Object(x,y)
    };
    
        

    提交回复
    热议问题