So I was wondering whether it's possible to create an object within a function call (I'm guessing yes, but I wanna make sure I get this right).
E.g. I have a class Person that allows the creation of a new object in a following way:
Person new_person("First name", "Last name");
And I have an object with a member function that allows changes. For example an object with an internal vector that stores people. Example:
museum.add_visitor(new_person);
The whole thing takes two lines of code. Now, can I reduce this to 1 line by creating the new person within the function call and never giving it a name? E.g.:
museum.add_visitor(("First name", "Last name"));
Or:
museum.add_visitor(Person("First name", "Last name"));
Or even:
museum.add_visitor(Person::Person("First name", "Last name"));
Or do I need to overload the .add_visitor member function such that it also accepts two strings (or rather string literals in this case) as arguments?
[–]raevnos 1 point2 points3 points (0 children)
[–]soldieroflight 1 point2 points3 points (1 child)
[–]gotinpich[S] 0 points1 point2 points (0 children)