【发布时间】:2011-10-20 03:31:20
【问题描述】:
这可能是一个关于继承的愚蠢问题,但对于为什么不允许我这样做并没有多大意义。我继承的基类是std::string:
class A : public std::string
当我使用class A 时,我想这样做:
A text;
std::string str = "hello";
text = str;
编译器抱怨没有二元运算符= 来执行此操作。
我想从字符串继承的原因是添加一些额外的功能,但不会丢失std::string 默认提供的功能。
基类不能自动分配给子类有什么原因吗?
谢谢。
【问题讨论】:
标签: c++ inheritance operators operator-overloading