c++ - Problems inheriting operator* -
i've been having troubles trying inherit operators in c++, using vs2013. have class implements several methods , class b inherits a. class implements operator * interacts class c, like:
class { ... c operator*(const c &_objectc) {...} } class b: public { ... }
since changes between , b don't change implementation of operator *, nice inherit instead of re-implement it. i've been trying that, compiler can't find operator implemented a.
in following code:
b foo = ...; c bar = ...; c result = foo * bar;
i'm having error:
error c2679: binary '*' : no operator found takes right-hand operand of type 'class c' (or there no acceptable conversion)
i know operator= has overloaded because compiler generates version of each class, can't inherit directly.
¿can other operators inherited? understanding possible, compiler doesn't agree. ¿is there i'm doing wrong or have re-implement operator call parent class's operator?
thanks in advance.
the following code, equivalent have presented (at time of writing answer), semicolons added , main
function filled out, works:
class c {}; class { public: auto operator*( c const &_objectc ) const -> c { return c(); } }; class b: public { }; auto main() -> int { b foo = b(); c bar = c(); c result = foo * bar; }
hence have not provided code problem is.
Comments
Post a Comment