Reputation: 856
I am from java/C# background and I am trying to understand some C++ code. I learned that a code like following is defining a function out of the class file
Some_Class::someFunction ( void ){
//SOME LINE
//OF CODE
//FOR THIS FUNCTION
}
I am using Visual Studio 2010 to build the project. However, when I debug it to understand the flow, I see something like abc::def::ghk::The_Class::theFunction() at line 999
in Call Stack of VS. Now, I am able to find The_Class::theFunction( void ){//SOME CODE}
definition in a class file Strange.cxx
.
Based on my learning I think abc, def and ghk are classes but I am unable to find a definition like class abc or class def.
My question is why Call Stack in VS show like this and what's their purpose/meaning?
Upvotes: 0
Views: 411
Reputation: 122830
::
is the scope resolution operator. I suppose this wont help you much, so I will try to put it in simple terms.
abc::def::ghk::The_Class::The_Function()
This is the full name (*) of The_Function()
. Suppose it is a method of The_Class
as in your snippet. Then this class might be nested inside another class called ghk
:
struct ghk {
struct The_Class {
void The_Function();
};
};
You can nest classes inside nested classes until the doctor comes.
Next, C++ uses namespaces to organize names. For example all standard library is in the namespace std
, the boost library puts its names in the namespace boost
. In this way you can have a foo
in boost and a foo
in the standard library and you can still tell them apart because their full name is boost::foo
and std::foo
. Namespaces can be nested as well.
One hypothetical declaration of The_Function
could be
namespace abc {
namespace def {
struct ghk {
struct The_Class {
void The_Function();
};
};
}
}
::
in front. For example ::foo
is the name of a foo
declared in the global scope (it is not placed inside a namespace).Upvotes: 2
Reputation: 1
My question is why Call Stack in VS show like this ...
Because the call stack shows you the fully qualified function symbol where you came from.
... and what's their purpose/meaning?
Multible appearance of symbol parts delimited by double colons ::
, indicates that the class or function declaration is embedded into a namespace or another class, e.g.:
namespace abc {
namespace def {
namespace ghk {
class The_Class {
void The_Function();
};
}
}
}
or
class abc {
class def {
class ghk {
class The_Class {
void The_Function();
};
};
};
};
or mixed
namespace abc {
namespace def {
class ghk { // No namespace definitions allowed inside.
class The_Class {
void The_Function();
};
};
}
}
I think Java has the same feature for exactly the same purpose:
Distinguish class names from appearing in different namespaces / packages.
Upvotes: 1