小编And*_*man的帖子

在C++中继承operator =的麻烦

我遇到了operator =的继承问题.为什么这段代码不起作用,解决它的最佳方法是什么?

#include <iostream>

class A
{
public:
    A & operator=(const A & a)
    {
        x = a.x;
        return *this;
    }

    bool operator==(const A & a)
    {
        return x == a.x;
    }

    virtual int get() = 0; // Abstract

protected:
    int x;
};

class B : public A
{
public:
    B(int x)
    {
        this->x = x;
    }

    int get()
    {
        return x;
    }
};

class C : public A
{
public:
    C(int x)
    {
        this->x = x;
    }

    int get() …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance abstract-class operator-keyword

17
推荐指数
1
解决办法
6012
查看次数