Is it possible to inherit identically named operator which only differ in return type, from two different abstract classes. If so, them:
what is the syntax for implementing operators
what is the syntax for using/resolving operators
what is the overhead in general case, same as for any other virtual function?
if you can provide me with a reference or sample code that would be helpful
thanks
12struct abstract_matrix {
13 virtual double& operator()(int i, int j);
14};
15
16 struct abstract_block_matrix {
17 virtual double* operator()(int i, int j);
18 };
19
20struct block_matrix : abstract_matrix, abstract_block_matrix {
21
22};
block matrix needs to provide implementations for both operators, so that it is either a matrix or a block matrix, depending on the context. I do not know how to provide implementation specific to block_matrix class. right now, it is done by passing object wrapped type as the last argument, but that does not seem very clean. I would like to retain pure matrix notation.
The return type of a function is not part of it's signature, so you can't have two operator+(i,j)'s in block_matrix - that would be an ambiguous call. So multiple inheritance is sort of a red herring here on this point. You just can't do that.
What are you really trying to do, and why?
In any event, for your other question: virtual operators are exactly like virtual functions in terms of performance and the way they operate. There are just slight semantic differences in how you use them - but under the hood they're just functions like any other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With