Definition recognized as a function-declaration

118 Views Asked by At

I've got a local variable inside a function:

vector<extend_t> newExtends( extend_alloc_t( alloc ) );

Unfortunately it gets recognized as a function definition. How do I prevent that ?

2

There are 2 best solutions below

0
Some programmer dude On

Simple solution: Use copy-initialization with = instead, as in:

auto newExtends = std::vector<extend_t>( extend_alloc_t( alloc ) );

[Note that actual copying should be elided]

2
justANewb stands with Ukraine On

You can use{}

std::vector<extend_t> newExtends = std::vector<extend_t>{extend_alloc_t(alloc)};