Template array initialization with a list of values

前端 未结 5 1229
一向
一向 2021-01-14 14:14

In standard c++ we can write :

int myArray[5] = {12, 54, 95, 1, 56};

I would like to write the same thing with a template :



        
5条回答
  •  暖寄归人
    2021-01-14 14:53

    It's actually very trivial; just remove the constructors and make the data members public. The template issue is a red hering; the same rules apply as for any class: if it is an aggregate, you can use aggregate initialization; if it's not, you can't.

    -- James Kanze

提交回复
热议问题