小编Gia*_*tta的帖子

关于多继承和定义虚函数

我有一个没有虚拟基类的多继承场景,如下所示:

 Ta  Tb
 |   |
 B   C
  \ /
   A
Run Code Online (Sandbox Code Playgroud)

Ta和Tb是两个不同的模板类,它们都声明了一个名为f()的虚函数.我想覆盖A范围中的两个函数,因为我必须在这些方法中与B和C数据进行交互.但我不知道该怎么做.

class Tb {
protected:
    virtual void f() {};
public:
    void call() {
        this->f();
    };  
};

class Tc {
protected:
    virtual void f() {};
public:
    void call() {
        this->f();
    };
};

class B : public Tb {
public:
    void doSomething() {};
};

class C : public Tc {
private:
    int c;
public:
    void inc() { c++; };
};

class A : public B, public C {
protected:
    void f() { …
Run Code Online (Sandbox Code Playgroud)

c++ virtual-functions multiple-inheritance

13
推荐指数
2
解决办法
1356
查看次数

错误:'operator []'未定义

我在使用g ++编译我的库中与operator []相关的片段时遇到了问题.

我用这段代码重新创建了同样的问题:

    template<class A,class B> class X {
    public: 
        template<class C> X<C,B>& operator[]( const C& );
    };

    template<class A,class B,class C> class Y : public X<C,B> {
        friend X<C,B>& X<A,B>::template operator[]<C>( const C& );
    private:
        Y( X<A,B>& object , const C& index ) : X<C,B>() {};
    };

    template<class A,class B> template<class C> X<C,B>& X<A,B>::operator[]( const C& index ) {
        return *( new Y<A,B,C>( *this , index ) );
    }

    int main() {
        X<int,void> x;
        X<int,void>& y = x[2]; …
Run Code Online (Sandbox Code Playgroud)

c++ templates operator-overloading

8
推荐指数
1
解决办法
680
查看次数

判断 make 是在 windows 还是 linux 上运行

有没有办法在 makefile 中知道 GNU make 是在 linux 操作系统还是 windows 操作系统上运行?

我已经构建了一个 bash 脚本,它生成一个用于构建我的应用程序的 makefile,它在我的 Debian 机器上运行良好。我想尝试在 MinGW/MSYS 上构建它,但问题是我必须构建和运行一些测试程序来检查源代码中的错误,而要在 Windows 上运行它,我必须添加 .exe 后缀。

makefile gnu-make os-agnostic os-detection

7
推荐指数
2
解决办法
1万
查看次数