-1

I'm looking through the source code for the v8 javascript engine (here's the github link), and on line 33 of parsing.cc, there's this statement within a function:

Parser parser(info);

I'm only used to seeing a type declaration like this before an assignment, such as:

Parser myparser = Parser(...);

So what does the first example do? Why not just invoke parser(info) without a type declaration?

Thank you in advance.

James M. Lay
  • 2,270
  • 25
  • 33

2 Answers2

4

The line

Parser parser(info);

constructs a Parser object by calling the constructor that takes info as the argument.

This method of constructing an object is called direct initialization.

You may also use the form

Parser parser = Parser(info);

to construct the object. This method of constructing an object is called copy initialization.

R Sahu
  • 204,454
  • 14
  • 159
  • 270
0

You are constructing an object of type Parser on the stack. (or as the comments say depending on the block scope this could be a global variable, not able to discern from the info available but more than likely it is the stack :) Object creation on the stack/heap?

9Breaker
  • 724
  • 6
  • 16