Return brace list elements – what is this?

This code snippet works, the question is why.

#include <iostream>
#include <string>
#include <vector>
#include <map>

class A {
  double something;
  std::vector<int> lol;

class B {
  std::map<int, char> lol2;

struct TwoClasses {
    A a;
    B b;

TwoClasses myfunc() {
 A obj1;
 B obj2;
 return {obj1, obj2};
        ^^^^^^^^^^^^ Isn't this aggregate initialization?

int main()
    TwoClasses dd = myfunc();

How come I can return two classes as in the following line

return {obj1, obj2};

those classes aren’t aggregates I suppose.

Source: New Questions

Leave a Reply