This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Easiest way to extend Vector2d to Vector3d by adding zero

Tags: None
(comma "," separated)
kamre
Registered Member
Posts
6
Karma
0
Hello!

Suppose there is a Vector2d instance and we need to pass it to function expecting Vector3d:
Code: Select all
void someFunc(const Vector3d& vec);
...
Vector2d some2DVector(1, 2);
somFunc(Vector3d(some2DVector.x(), some2DVector.y(), 0));

Is there a better and more concise way to do this? May be using blocks or something like that?

Last edited by kamre on Fri Dec 09, 2016 2:24 pm, edited 1 time in total.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Code: Select all
Vector2d a;
Vector3d b;
b << a, 0;
kamre
Registered Member
Posts
6
Karma
0
May be its good for initializing a new vector but its not that good for function call:
Code: Select all
void someFunc(const Vector3d& vec);
...
Vector2d some2DVector(1, 2);
somFunc((Vector3d() << some2DVector, 0).finished());

Any other ways?


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]