this is super strange...
I have this function here:
template<typename TFirst, typename... TArgs>
bool util::LogConsole(const TFirst& first, const TArgs&... rest)
{
std::cout << first << " ";
return LogConsole(rest...);
}
bool util::LogConsole()
{
std::cout << std::endl;
return false;
}
it's recursive, keep printing "first" and recursively sending the rest, until rest is empty and the overload taking no argument is called, which just print a newline. Ignore the bool return.
Anyway, now I have this code somewhere else:
for (auto& E : Entities) {
float valx = E->GetPosition().x;//return 751
float valy = E->GetPosition().y;//return 838
LogConsole(valx, valy);
}
Entities is a vector<unique_ptr<Entity>> which currently only contains the derived from Entity player Paddle, so I access the Base class Entity method called GetPosition, which is the center pivot coordinates of the object.
I pass the variable to LogConsole which predictably prints:
But not I try to call LogConsole without those 2 variables inbetween, like this:
for (auto& E : Entities)
{
LogConsole(E->GetPosition().x, E->GetPosition().y);
}
and watch what kind of output I get! :
... the y value is an unreasonable value o_o
How is this even possible?! Since only the second value is being affected, my assumption is that there is some weird interplay with the second template parameter, the variadic argument...but I wasn't able to debug it even stepping trough it line by line...can anyone come with an explanation for this really strange behaviour?
↧