本文介绍了STL字符串继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 Hello社区, 我使用STL还不错,但我一直在试验它。 我尝试过从字符串派生一个新类说MyString如下: class MyString:public string { public: MyString( ){} }; 当我尝试做的时候: MyString MyStringInstance; MyStringInstance =" BlaBlaBla"; 它呻吟: 错误C2679:二进制''='':没有找到哪个运算符一个右手操作数 类型''const char [9]''(或者没有可接受的转换) MyStringInstance + =" BlaBlaBla" ;; 和 string MyStringInstance; MyStringInstance =" BlaBlaBla"; 工作正常。 为什么= My运算符在MyString中不可用? 感谢您的帮助,迈克:) P.S.我正在使用MS Visual C ++ .NET Hello community, i''m fairly new to using the STL but i''ve been experimenting a bit with it.I tried to derive a new class say MyString from string like so: class MyString: public string{public:MyString(){}}; when i then try to do: MyString MyStringInstance;MyStringInstance = "BlaBlaBla"; it moans:error C2679: binary ''='' : no operator found which takes a right-hand operandof type ''const char [9]'' (or there is no acceptable conversion) MyStringInstance += "BlaBlaBla"; and string MyStringInstance;MyStringInstance = "BlaBlaBla"; works fine though. Why is the = operator not available in MyString ?? Thanks for any help, Mike :) P.S. I''m using MS Visual C++ .NET 推荐答案 operator =()不是派生类直接继承的,它是 标准C ++行为(恕我直言) Fabio operator=() is not directly inherited by the derived class, it is thestandard C++ behaviour (IMHO) Fabio 新闻:I4 ******** @ bath.ac.uk ... news:I4********@bath.ac.uk... 操作数 运算符=()不是由派生类直接继承的,它是标准C ++行为(恕我直言) Fabio operator=() is not directly inherited by the derived class, it is the standard C++ behaviour (IMHO) Fabio 垃圾!当然是。 / Peter Rubbish! Of course it is./Peter 这篇关于STL字符串继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-10 08:05