I’m trying to implement a form of reflection in C++ for a project. The idea is that you register classes with tags into a map as a sort of template, then call the cloneNew method of the shared base class to actually create the object that you want. However when I try to use a va_list to implement this functionality I get weird results. The problem code is:
GameObject* SphereObstacle::cloneNew(const Vector& position, double charge, const Vector& dipole, ...)
{
va_list v1;
va_start(v1, dipole);
double radius = va_arg(v1, double);
va_end(v1);
return new SphereObstacle(position, charge, dipole, radius);
}
Every time I try to read from the va_list it returns a value that is huge. It almost seems like its a pointer. My only thought is that the issue is caused by the fact that this is an implementation of a virtual method in the base class, but I haven’t found anything online to suggest that that is the issue. What is it that I am doing wrong?
The problem is with
dipolebeing of a reference type. Regardingva_start, citing [support.runtime]/3: