-1

I have the below piece of code. I want to create an object Model outside my main and then use it inside main method. However, VS keeps confusing my object initialization with a function declaration and doesnt allow me to use it. Is there a way to initialize it without the compiler confusing between the two?

Model model();

int main{
    model.loadModel("testModel.txt"); // I want to do st like this, but it causes error
}

How can I fix this?

Manh Nguyen Huu
  • 331
  • 1
  • 4
  • 12

2 Answers2

5

Because this line:

Model model();

will be parsed to a function declaration, this is the most vexing parse.

You need

Model model;

or

Model model{};
llllllllll
  • 16,169
  • 4
  • 31
  • 54
2
Model model();

To the compiler this looks like a function declaration that returns a Model and takes no parameters.

Try removing the ():

Model model;
Hatted Rooster
  • 35,759
  • 6
  • 62
  • 122