3 ms·
Go would do: v := []TYPEHERE{1, 2, 3} where TYPEHERE is the type of array[1] that you're creating. Is there any equivalent C++ technique here? Explaining
by jerf 12y ago
Go would do:
v := []TYPEHERE{1, 2, 3}
where TYPEHERE is the type of array[1] that you're creating. Is there any equivalent C++ technique here? Explaining all the machinery may blow out a novice's mind, but I think explaining "You need to give C++ some clue about the type" isn't so bad.
[1]: Before you complain I just created a slice, remember the slice has to point at an array; I've created both a slice and an array so it's not "wrong" to say I've created an array with that syntax.
- TheCoelacanth 12y agoYes, C++ has no shortage of ways to initialize variables. Any of these should work TYPENAME v {1, 2, 3}; TYPENAME v = {1, 2, 3}; auto v = TYPENAME {1, 2, 3};