0

I have the following structure in the code:

while (x > 0) {
     something;
     aaa::bbb::ccc some_name(
        x,
        y
     );
}

I cannot understand what aaa::bbb::ccc some_name(. If it is a call of function, why do we need to specify its time aaa::bbb::ccc. If it is a declaration of a function, why it is done in while loop and why types of the arguments are not specified?

Roman
  • 124,451
  • 167
  • 349
  • 456

3 Answers3

3

You don't specify the return type in function calls, so this cannot possibly be a function call.

As Pubby points out, it is very likely an object definition. You define an object called some_name of type aaa::bbb::ccc and pass x and y to the constructor.

fredoverflow
  • 256,549
  • 94
  • 388
  • 662
2

In this particular case, it's probably constructing an object some_name of type aaa::bbb::ccc by calling its two-parameter constructor with arguments x and y.

The reason why it's done in the loop could be that the object does some useful work in its constructor and/or destructor (it could e.g. be some form of scope guard).

Angew is no longer proud of SO
  • 167,307
  • 17
  • 350
  • 455
  • Of course, if `x` and `y` name types, it _is_ a function declaration. In simple cases like this, it's usually pretty obvious (and naming conventions help). In more complicated cases, it can be ambiguous---see "most vexing parse". – James Kanze Mar 12 '13 at 09:29
0

I am not quite sure what you are up to, but the

::

in C++ is called the scope-operator and is used to access namespaces, variables in namespaces or static class-members.

Usually function-declarations and definitions appear outside of functions and methods. So your code doesn't make any sense.

See here about the scope-operator. And here for declaration vs definition.

bash.d
  • 13,029
  • 3
  • 29
  • 42
  • "Usually declarations and definitions appear outside of functions"? I certainly make extensive use of local variables, and this looks very much like the definition of a local variable. – James Kanze Mar 12 '13 at 09:31
  • @JamesKanze I am sorry, I was not specific enough. I was talking about **function**-declarations and definitions. Thank you for the hint. – bash.d Mar 12 '13 at 09:33