Let's say I have a class:
class Aggregate {
public:
int x;
int y;
};
I know how to initialize an object using curly braces:
Aggregate a1 = { 1500, 2900 };
But I can't find a proper syntax to create temporary object and pass it as an argument to some method, for example:
void frobnicate(const Aggregate& arg) {
// do something
}
//...
frobnicate(Aggregate {1500, 2900}); // what should this line look like?
The easiest way would be to add the constructor to Aggregate class, but let's assume I don't have an access to the Aggregate header. Another idea would be to write some kind of factory method, i.e.
Aggregate makeAggregate(int x, int y).
I can also create an object and then pass it as an argument, etc. etc.
There are many solutions, but I'm just curious if it's possible to achieve this goal using curly braces initialization.