下标运营商 [英] Subscript Operator
问题描述
我希望有人可以提供帮助。
我有一个名为cField的类,另一个名为cFieldList的类。
cFieldList包含一个名为myvec的std :: vector of cField
我已经为cFieldList重载了下标运算符:
cField& operator [](int pos){return myvec [pos];然而,当我编译以下代码时,我收到一个错误:
cField f = MyFieldList [1];然而,
//这个例子,假设对象存在
正确
编译器返回 - 无法找到''cField :: operator
=(cFieldList)''
有人想知道我做错了吗?
提前谢谢,
史蒂夫。
2004年4月30日星期五16:36:21 + 0100,史蒂夫 < ST ******* @ hotmail.com>写道:
我希望有人可以提供帮助。
我有一个名为cField的类,另一个名为cFieldList的类。
> cFieldList包含一个名为myvec的cField的std :: vector
我已经为cFieldList重载了下标运算符:
cField& operator [](int pos){return myvec [pos];但是,当我编译以下代码时,我收到一个错误:
cField f = MyFieldList [1]; //这个例子,假设对象存在正确
编译器返回 - 找不到匹配''cField :: operator
=(cFieldList)''
任何人都有任何想法,我做错了什么?
编号因此,请给我们一个完整的工作程序,将其缩小至最小值
绘制错误。我会说你至少有50%的机会在你到达发布点之前自己解决问题
你的代码;-)
-leor
提前致谢,
史蒂夫。
-
Leor Zolman --- BD软件--- www.bdsoft.com
C / C ++,Java,Perl和Unix的现场培训
C ++用户:下载BD Software的免费STL错误消息解密器:
www.bdsoft.com/tools/stlfilt.html
2004年4月30日星期五16:46:33 GMT,Leor Zolman< le ** @ bdsoft.com>写道:
任何想法我做错了什么?
没有因此,请给我们一个完整的工作程序,将其缩小至最小值,以便绘制错误。我会说你至少有50%的机会在你发布你的代码之前自己解决问题;-)
- leor
嘿......好吧,它不一定要工作。 (Duh)
-leor
提前致谢,
Steve。
>
-
Leor Zolman --- BD软件--- www.bdsoft.com
C / C ++,Java,Perl和Unix的现场培训
C ++用户:免费下载BD Software' STL错误消息解密器:
www.bdsoft.com/tools/ stlfilt.html
我不知道这是否有帮助,但我会尝试使用:
const cField& operator [](int pos){return myvec [pos]; }
问候,
Nils
-
http://www.nilsschneider.de (音乐,留言簿,工作室,工具......)
Hi, I hope someone can help.
I have a class called cField, and another class called cFieldList.
cFieldList contains a std::vector of cFields called myvec
I''ve overloaded the subscript operator for cFieldList as so:
cField& operator[](int pos) { return myvec[pos]; }
however, when I compile the following code, I get an error:
cField f = MyFieldList[1]; // this an example, assume the objects exists
correctly
The compiler returns - Could not find a match for ''cField::operator
=(cFieldList)''
Anybody any ideas what I''m doing wrong?
Thanks in advance,
Steve.
On Fri, 30 Apr 2004 16:36:21 +0100, "Steve" <st*******@hotmail.com> wrote:
Hi, I hope someone can help.
I have a class called cField, and another class called cFieldList.
cFieldList contains a std::vector of cFields called myvec
I''ve overloaded the subscript operator for cFieldList as so:
cField& operator[](int pos) { return myvec[pos]; }
however, when I compile the following code, I get an error:
cField f = MyFieldList[1]; // this an example, assume the objects exists
correctly
The compiler returns - Could not find a match for ''cField::operator
=(cFieldList)''
Anybody any ideas what I''m doing wrong?
No. So give us a complete working program whittled down to the minimum it
takes to draw the error. I''d say you''ve got at least a 50% chance of
figuring out the problem on your own before you get to the point of posting
your code ;-)
-leor
Thanks in advance,
Steve.
--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software''s free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
On Fri, 30 Apr 2004 16:46:33 GMT, Leor Zolman <le**@bdsoft.com> wrote:
ody any ideas what I''m doing wrong?
No. So give us a complete working program whittled down to the minimum it
takes to draw the error. I''d say you''ve got at least a 50% chance of
figuring out the problem on your own before you get to the point of posting
your code ;-)
-leor
Heh...OK, it doesn''t have to be "working" (Duh)
-leor
Thanks in advance,
Steve.
--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software''s free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
I don''t know if this helps, but I would try to use:
const cField& operator[](int pos) { return myvec[pos]; }const
Regards,
Nils
--
http://www.nilsschneider.de (Music, Guestbook, Studio, Tools, ... )
这篇关于下标运营商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!