What does the :: mean in C++? [duplicate]
void weight_data::rev_seq(string &seq){
//TODO
std::reverse(seq.begin(), seq.end());
}
In this C++ method, I think this method does not return anything, so the prefix is void
, what does ::
tell the relationships between weight_data
and rev_seq(string &seq)
? Thanks!
void
is the return type. ::
is the scope resolution operator, so it means rev_seq
is inside the scope of weight_data
. weight_data
could be either a namespace or a class (based on what you've given, it's not possible to say which).
In C++,
-
A::B
meansB
is an identifier within eithernamespace
orclass
typeA
, -
A.B
meansB
is a member of thestruct
,class
, orunion
type an instance of which is referred to by the object or referenceA
, and -
A->B
meansB
is a member of thestruct
,class
, orunion
type an instance of which is referred to by the pointerA
. (It's equivalent to(*A).B
.)
In some other languages, all three cases are covered by a .
only.
Note that in C++, member function don't have to be implemented (defined) within their class' definition. (If they are, they are implicitly inline
.) They can be, and often are, implemented in separate implementation (.cpp
) files. This has the advantage that not all users of a class need to recompile when you change an implementation of one of the class' member functions. So unless weight_data
is a namespace
name, void weight_data::rev_seq(string &seq) {...}
is such a definition of a class member outside of its class.
weight_data
is a namespace or class name.