【发布时间】:2011-04-27 15:12:20
【问题描述】:
我想调用某个类的特定基类的特定运算符。对于简单的功能很容易:我只写SpecificBaseClass::function( args );。我应该如何为操作员实现相同的功能而不需要施放诡计?
孤立的问题:
class A
{
public:
A operator+( const A &other ) const {...}
};
class B : public A
{
public:
B operator+( const B & other ) const {...}
};
...
B a, b;
B c = A::operator+( a, b ); //how this should be implemented? I get an error
...
我从 GCC4.5.1 收到以下错误:
error: no matching function for call to ‘A::operator+(B&, B&)’
note: candidate is: A A::operator+(const A&) const
谢谢!
编辑
我已经改进了示例以更好地说明问题。
【问题讨论】:
标签: c++ inheritance function operators