E. Zacarias E. Zacarias - 4 months ago 24
C++ Question

Weird C++ syntax: type definition before a function call

I was reading NodeJS and V8 source, particulary

file, and I could not understand the following line:

Context::Scope context_scope(debug_context);

I don't understand what is that
before what seems to be a function call. I don't think it is a declaration because it is a function code, together with an
and other calls.

Complete relevant code:

if (debug_context.IsEmpty()) {
// [... lines removed for brevity ...]
Context::Scope context_scope(debug_context);
MaybeLocal<Script> script = Script::Compile(debug_context, script_source);
if (script.IsEmpty())
return; // Exception pending.

What is the meaning of that

Further information:

File: node/node_contextify.cc (the line 268 is highlighted).

While I understand it is a basic question about syntax, I don't even know how to call it, so I was not able to find any result in Google, StackOverflow or C++ reference.

The question title is one of my attempts when searching for it.


It's initializing the context_scope variable with debug_context. Context::Scope is the type (here's one ref page http://bespin.cz/~ondras/html/classv8_1_1Context_1_1Scope.html)

Here's another article on using Context::Scope How to correctly use Context::Scope ?

BTW, even if you don't know what to call it, searching for "v8 Context::Scope" will turn up information.