I am moving from c to c++ and came across scoperesolution page info here and was quite helpful What does "ClassName ClassName::FunctionName" mean in C++?
But I also came across the following code which I am planning to learn and it has a pointer before class name, so my question is in what circumstance would one use the pointer.
const char *TObject::ClassName() const
{
// Returns name of class to which the object belongs.
return IsA()->GetName();
}
This is a regular definition of a member function outside of its class. The asterisk has no special meaning in this context.
First, recall how you define a function in C that returns a pointer:
const char *Foo() {
return something;
}
The declaration that you see has the same structure, except for two elements:
const
after the function. What scope resolution means is that ClassName
is a member-function belonging to class TObject
, and the const
at the end means that the code of the member-function does not alter member variables of its class.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.