| |||
Home > DS-5 Debugger commands > General syntax and usage of DS-5 Debugger commands > Using the C++ scoping resolution operator |
In C++, the ::
(scope resolution) operator
is a global identifier for variable or function names that are out
of scope.
The expression evaluator supports scoping operations using the scope resolution, member and member pointer operators. This can be used to reference variables and functions within files, namespaces or classes.
For example:
Example 5. demo.cpp
static int FILE_STATIC_VARIABLE = 20; class OuterClass { public: OuterClass(int i) { value = i; } class InnerClass { public: int demoFunction() { return 25; } }; void increment() { value++; } int value; }; namespace NAME_SPACE_OUTER { const int TEST_VAR= 20; namespace NAME_SPACE_INNER { const int TEST_VAR= 19; int nameSpaceFoo () { return 60; } }; }; int main() { OuterClass oc(14); OuterClass *ptr_oc = &oc; ptr_oc->increment(); }
You can query this example by using any of the following expressions:
OuterClass::InnerClass::demoFunction "demo.c"::FILE_STATIC_VARIABLE NAME_SPACE_OUTER::TEST_VAR NAME_SPACE_OUTER::NAME_SPACE_INNER::TEST_VAR
If you set a a breakpoint at ptr_oc->increment()
and
run to it, then the following expressions can also be used to query
the instances of the outer class:
oc.value ptr_oc->value