I saw a video about templates in c++ the other day and it had the following code:
template <typename T>
void someFunction(T num) {
Print(num);
}
The "Print()" just prints out the var "num" in console. I basically understood how to use templates as parameters. However, I don’t know how to use this with Structs, or if it’s even possible. I mean something like this:
struct vec2 {
float x, y;
};
struct vec3 {
float x, y, z;
};
template <typename T>
void someFunction(T vec);
I want to check in the function whether "vec" is a vec2 or a vec3 and then use it differently. Like this:
if (vec==vec2) {
//Print x and y
else if (vec==vec3) {
//Print x, y and z
}
In the end my goal is simply to have a function that I can give 2 different structures to. I already heard about std::is_same and tried it but without any success.