I've noticed with some functions in C++ that accept objects (e.g. constructors), you can actually create the object within the function argument e.g. (this example uses an SDL_Point as the main parameter)
//Constructor for custom object
object::object(SDL_Point spawn_location);
//Declaration of new object
SDL_Point new_point {0, 0};
object new_object(new_point);
//Alternatively, this also works
object new_object(SDL_Point{0, 0});
My question is, is this also possible with derived classes? My thinking behind this is that I have a single base class with a large number of derived (and derived derived etc) classes that I'd like to instantiate using a single function (to set various variables and add to a common vector). Current this looks like this:
void create_new_object(base_class object_to_create)
{
//Do new object stuff
}
This works:
my_derived_class new_object;
create_new_object(new_object);
However, I get an error (expected primary-expression before new_object) with this:
create_new_object(object new_object);
Is this strictly a base / derived class issue, a difference between functions and constructors, or is there something more I need to do to allow the function to accept the instantiation of objects within its parameters?
Thanks
Nathan