Reputation: 8827
I am initialising a c style struct using a list:
FooBar fb = { 12, 3.4 };
this works fine, but how would i create the struct dynamically using this curvy brace notation?
thanks
Upvotes: 1
Views: 1754
Reputation: 254451
In C++11,
std::unique_ptr<FooBar> fb {new FooBar {12, 3.4}};
In C++03, you can't.
Upvotes: 3
Reputation: 53037
C++11:
FooBar* fb = new FooBar{ 12, 3.4 };
You can also use it in containers:
std::vector<FooBar> v;
v.push_back({ 12, 3.4 });
Upvotes: 3