metaclay2
April 21, 2018 03:34:16
Hi , what is the difference between these 2 vector assignments :
vector myVect = set(1,2,3);
vector myVect = {1,2,3};
Thanks
metaclay2
April 21, 2018 15:09:12
matthias_k
In this case nothing
but:
float foo = 0.5;
vector myVect = set(1,foo ,3); // will work
vector myVect = {1,foo ,3}; // errors out
Yes, that's what confused me. The “{}” can't take variable … is it design like that or is it a bug ?
BabaJ
April 21, 2018 19:42:30
It's neither by design or a bug.
Perhaps you could say it is ‘by design’ indirectly;
The curly braces are not a “function” - they are simply part of a syntax structure that we can use in certain contexts, in this case along with the combination of = , and ; characters that allow us to assign values to ‘myVec’.
There's nothing to tell the compiler what foo is or how it should be handled, to do that, we need a simple function;
like say - the set() function, that can handle what foo is.
All you more knowledgeable people out there - please do chime and correct me or rephrase/add to what I've said if wrong.