小编Ana*_*rki的帖子

C++"virtual"关键字,用于派生类中的函数.有必要吗?

使用下面给出的结构定义......

struct A {
    virtual void hello() = 0;
};
Run Code Online (Sandbox Code Playgroud)

方法#1:

struct B : public A {
    virtual void hello() { ... }
};
Run Code Online (Sandbox Code Playgroud)

方法#2:

struct B : public A {
    void hello() { ... }
};
Run Code Online (Sandbox Code Playgroud)

这两种覆盖hello函数的方法有什么区别吗?

c++ overriding virtual-functions

211
推荐指数
6
解决办法
7万
查看次数

C++双地址运算符?(&&)

我正在阅读STL源代码,我不知道&&运算符应该做什么.以下是一个代码示例stl_vector.h:

vector&
operator=(vector&& __x) // <-- Note double ampersands here
{
    // NB: DR 675.
    this->clear();
    this->swap(__x); 
    return *this;
}
Run Code Online (Sandbox Code Playgroud)

"地址"是否有意义?为什么它有两个地址运算符而不是一个?

c++ stl memory-address operator-keyword

116
推荐指数
5
解决办法
9万
查看次数