STL字符串继承 [英] STL string inheritance

查看:80
本文介绍了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 operand
of 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


推荐答案



" Mike Tyka" <米**** @ gnx.net>在留言新闻中写道:I4 ******** @ bath.ac.uk ...

"Mike Tyka" <m.****@gnx.net> wrote in message news:I4********@bath.ac.uk...
你好社区,

我很擅长使用STL,但我一直在试验它。
我试图从字符串派生一个新类说MyString,如下所示:

类MyString:public string {
public:
MyString(){}
};

当我尝试做的时候:

MyString MyStringInstance;
MyStringInstance =" ; BlaBlaBla;

它呻吟:
错误C2679:二进制''='':找不到运算符,它接受一个类型''const char的右手
操作数[ 9]''(或没有可接受的转换)

MyStringInstance + =" BlaBlaBla";



字符串MyStringInstance;
MyStringInstance =" BlaBlaBla" ;;

但工作正常。

为什么= My运算符在MyString中不可用?

谢谢你任何帮助,迈克:)

PS我正在使用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 operand of 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 the
standard C++ behaviour (IMHO)

Fabio




" Fabio" < FA ************* @ libero.it> skrev i en meddelelse

新闻:2s ************* @ uni-berlin.de ...

"Fabio" <fa*************@libero.it> skrev i en meddelelse
news:2s*************@uni-berlin.de...

" ; Mike Tyka <米**** @ gnx.net>在消息中写道

"Mike Tyka" <m.****@gnx.net> wrote in message



新闻:I4 ******** @ bath.ac.uk ...


news:I4********@bath.ac.uk...

你好社区,

我对使用STL相当新,但我已经用
进行了一些实验。我试图从字符串派生一个新类说MyString如此:

类MyString:public string {
public:
MyString(){}
}; <当我尝试做的时候:

MyString MyStringInstance;
MyStringInstance =" BlaBlaBla" ;;

它呻吟:错误C2679:binary''='':找不到哪个操作符采用右侧
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


操作数

类型为''const char [9]''(或没有可接受的转换)

MyStringInstance + =" BlaBlaBla";



字符串MyStringInstance;
MyStringInstance =" BlaBlaBla;

但工作正常。

为什么= My运算符在MyString中不可用?

感谢您的帮助,Mike :)

PS我正在使用MS Visual C ++ .NET
of 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



运算符=()不是由派生类直接继承的,它是
标准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


Peter Koch Larsen在新闻中写道:K7f7d.54262
Peter Koch Larsen wrote in news:K7f7d.54262


这篇关于STL字符串继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆