Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #9188
| From | Nobody <nobody@nowhere.com> |
|---|---|
| Subject | Re: Operator overloading in memberclass. |
| Date | 2011-08-22 20:00 +0100 |
| Message-Id | <pan.2011.08.22.19.00.56.16000@nowhere.com> |
| Newsgroups | comp.lang.c++ |
| References | <6468f4d9-f386-43c6-a423-701d701bc1fa@glegroupsg2000goo.googlegroups.com> <9bdjf7Fr0aU4@mid.individual.net> <bf22dc5c-c7da-46f5-b6a5-54f8a9461c2c@glegroupsg2000goo.googlegroups.com> <a966101e-1a18-47b6-a6d3-e8c7f68b295e@d25g2000yqh.googlegroups.com> <4a5e99ea-d362-4c1e-8c33-51ca5ded9924@glegroupsg2000goo.googlegroups.com> |
| Organization | Zen Internet |
On Mon, 22 Aug 2011 10:15:20 -0700, Marz wrote:
> class Animation
> {
> Frame *FrameList;//List of frames for the animation Animation *
> void Animation::SetFrame(int index, Frame * frame) {
> FrameList[index]=frame;
> }
You're trying to assign a Frame* to a Frame. In C, this would be a
straightforward error. In C++, this is allowed, provided that you provide
a suitable operator= to perform the assignment. But you don't, hence the
error.
The above should be:
FrameList[index] = *frame;
But it would be better to change the interface to take a Frame& rather
than a Frame*, i.e.:
void Animation::SetFrame(int index, const Frame& frame) {
FrameList[index] = frame;
}
[This is assuming that FrameList is actually supposed to be an array of
Frames, not an array of pointers to Frames.]
In general, you shouldn't use pointers unless you actually need the
functionality of a pointer (e.g. the ability to change where it points, or
to perform pointer arithmetic). If a reference will suffice, use a
reference.
Also, consider using std::vector instead of pointers and malloc().
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Operator overloading in memberclass. Marz <marzkrishna@gmail.com> - 2011-08-21 15:26 -0700
Re: Operator overloading in memberclass. Ian Collins <ian-news@hotmail.com> - 2011-08-22 11:42 +1200
Re: Operator overloading in memberclass. Marz <marzkrishna@gmail.com> - 2011-08-21 20:17 -0700
Re: Operator overloading in memberclass. Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-08-22 04:12 -0700
Re: Operator overloading in memberclass. Marz <marzkrishna@gmail.com> - 2011-08-22 10:15 -0700
Re: Operator overloading in memberclass. Nobody <nobody@nowhere.com> - 2011-08-22 20:00 +0100
Re: Operator overloading in memberclass. Marz <marzkrishna@gmail.com> - 2011-08-22 14:28 -0700
Re: Operator overloading in memberclass. "Balog Pal" <pasa@lib.hu> - 2011-08-22 13:25 +0200
Re: Operator overloading in memberclass. Marz <marzkrishna@gmail.com> - 2011-08-22 10:19 -0700
Re: Operator overloading in memberclass. "Balog Pal" <pasa@lib.hu> - 2011-08-22 22:42 +0200
Re: Operator overloading in memberclass. Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-22 13:32 -0400
csiph-web