C++ 中的 :: 是什么意思?
void weight_data::rev_seq(string &seq){
//TODO
std::reverse(seq.begin(), seq.end());
}
在这个C++方法中,我认为这个方法不会返回任何东西,所以前缀是void
,::
告诉了weight_data
之间的关系和rev_seq(string &seq)
?谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
void
是返回类型。::
是范围解析运算符,因此意味着rev_seq
在weight_data
范围内。weight_data
可以是命名空间或类(根据您给出的内容,无法说出是哪个)。void
is the return type.::
is the scope resolution operator, so it meansrev_seq
is inside the scope ofweight_data
.weight_data
could be either a namespace or a class (based on what you've given, it's not possible to say which).在 C++ 中,
A::B
表示B
是namespace
或class 类型
A
,AB
表示B
是struct
的成员,class
或union
类型,其实例由对象或引用A
引用,并且A-> ;B
表示B
是struct
、class
或union
的成员> 键入一个由指针A
引用的实例。 (它相当于(*A).B
。)在某些其他语言中,所有三种情况都仅由
.
涵盖。请注意,在 C++ 中,成员函数不必在其类定义中实现(定义)。 (如果是,则它们是隐式
内联
。)它们可以而且通常在单独的实现 (.cpp
) 文件中实现。这样做的优点是,当您更改类的成员函数之一的实现时,并非该类的所有用户都需要重新编译。因此,除非weight_data
是一个namespace
名称,void Weight_data::rev_seq(string &seq) {...}
就是这样的定义班级之外的班级成员。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
, andA->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 unlessweight_data
is anamespace
name,void weight_data::rev_seq(string &seq) {...}
is such a definition of a class member outside of its class.weight_data
是一个 命名空间 或类名。weight_data
is a namespace or class name.void Weight_data::rev_seq(string &seq)
行告诉编译器这是rev_seq(string &seq)
成员函数的定义>权重数据。如果这只是说void rev_seq(string &seq) { ... }
编译器会认为正在定义一个非成员函数,而不是rev_seq(string & seq)
weight_data 类的成员函数。它还可能意味着
rev_str
引用属于命名空间weight_data
一部分的函数。The line
void weight_data::rev_seq(string &seq)
tells the compiler that this is the definition of therev_seq(string &seq)
member function from theweight_data
. If this just saidvoid rev_seq(string &seq) { ... }
the compiler would think that a non-member function was being defined, as opposed to therev_seq(string &seq)
member function of theweight_data
class.It can also mean that
rev_str
refers to a function that is part of namespaceweight_data
.只是想添加关于 ::
a) Operator :: 的
2 个更有趣的事情b) $10.3/12 - “使用范围运算符 (5.1) 的显式限定会抑制虚拟调用机制。”
Just thought of adding 2 more interesting things about the ::
a) Operator :: is both a unary and a binary operator
b) $10.3/12 - "Explicit qualification with the scope operator (5.1) suppresses the virtual call mechanism."