Can you really inherit in the same way named operator which only differ in exchange type, from two different abstract classes. If that's the case, them:

  • what's the syntax for applying operators

  • what's the syntax for implementingOrsolving operators

  • what's the overhead generally situation, same for every other virtual function?

if you're able to provide me having a reference or sample code that might be useful

thanks


12struct abstract_matrix 

 15

 16    struct abstract_block_matrix 

 19

 20struct block_matrix : abstract_matrix, abstract_block_matrix 

block matrix must provide implementations for operators, to ensure that it will be an matrix or perhaps a block matrix, with respect to the context. I don't understand how to provide implementation specific to bar_matrix class. at this time, to control your emotions by passing object wrapped type because the last argument, but that doesn't appear very clean. I must retain pure matrix notation.

You cannot overload around the return type. Whenever a function or perhaps an operator is invoked the compiler needs to know which to call. It won't infer that according to exactly what the function(operator) call designated to.

Appears like you're searching to implement some matrix math. Possibly should you download DirectX SDK or OpenGL and take a look the way they get it done, you can find some tips on how to get it done correctly.

The return kind of a function isn't a part of it's signature, which means you can't have two operator+(i,j)'s in block_matrix - that might be an ambiguous call. So multiple inheritance is kind of a red-colored sardines here about this point. You simply can't do this.

What exactly are you actually attempting to do, and why?

The point is, for the other question: virtual operators are the same as virtual functions when it comes to performance and exactly how they operate. You will find just slight semantic variations in how they are being used - but underneath the hood they are just functions like every other.

I first got it work, but it is wonky. I actually do love templates.

template<class T>
class Base1
{
};

template<class T>
class Base2
{
};

class Derived;
template<>
class Base1<Derived>
{
public:
     double foo(){return 0.1;}
};

template<>
class Base2<Derived>
{
public:
    int foo(){return 1;}
};

class Derived
    : public Base1<Derived>
    , public Base2<Derived>
{
public:
    using Base1<Derived>::foo;
};

int main()
{
     double sum = 0;
     Derived d;
     sum += d.foo(); //+ .1
     Base1<Derived> * pI = &d;
     sum += pI->foo(); //+ .1

     Base2<Derived> * pF = &d;
     sum += pF->foo(); //+ 1

     return (sum*10);
}

I could not get results without templates, even though it appears enjoy it should have the ability to. I am unsure if you're able to pull off just doing templated member functions very much the same, but my stomach states "no".

When it comes to code organization, I'd then define the bottomNumber stuff immediately after the meaning or promise of Derived, since that's really how it is for. Bear in mind after that you can use typename Base1<Derived> something to create things more attractive.

Edit: Oh, right! It does not permit you to perform the "using" trick or have different return types, but it is otherwise simpler:

class Derived
    : public Base1
    , public Base2
{
    double Base1::foo(){...}
    double Base2::foo(){...}
}

There might be a dreadful, horrible, awesome method to mix both of these approaches, however i don't believe it'll really help while using the code. I might respond on that.