Dynamically allocating class object with constructor arguments

Hello people!

I have a quick question.

Let's assume you have a class which constructor takes an argument
1
2
Foo::Foo(int)
{...}


Now let's say you want to dynamically allocate an object of the Foo class. Foo* fooObject;


What is the correct syntax to create the object with the necessary arguments for the constructor?
1
2
3
int argument;

fooObject = new Foo(argument); //? 


Thanks in advance,

Regards,

Hoogo.
Last edited on
What does your compiler say about your syntax?

You seem to use direct initialization: https://en.cppreference.com/w/cpp/language/direct_initialization
There is also list initialization: https://en.cppreference.com/w/cpp/language/list_initialization
Oh thank you for the reference, that helped. I wasn't able then, to test it so I thought I might ask directly the question out of curiosity.

Turns out this was indeed the right syntax!

Thanks for your time!

Topic archived. No new replies allowed.