Well I've been reading this book, Programming Game AI by Example (great book by the way, I'd highly reccommend it =D). Anyways I've noticed the use of copy constructors, and I've seen them from Sam's Teach Yourself C++ in an Hour a Day, but it barely touches on it. I looked around through Google, but I still don't understand the purpose of copy constructors.
So can anyone give an explanation on them?
Copy Constructors 0.o?
Moderator: Coders of Rage
Re: Copy Constructors 0.o?
The copy constructor is always implemented, even if you don't write it down in your class. However, if it does not do what you want, you are free to make your own implementation of it.
Re: Copy Constructors 0.o?
K-Bal wrote:The copy constructor is always implemented, even if you don't write it down in your class. However, if it does not do what you want, you are free to make your own implementation of it.
Found an Article that explains everything =D
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: Copy Constructors 0.o?
In response to your strikethrough =) They're for copying things. You don't have to implement your own unless you need a deep copy (as opposed to a shallow copy), or other special treatment.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Copy Constructors 0.o?
I recommend always passing (especially large) objects by reference.
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: Copy Constructors 0.o?
Right, but if you want a copy of something to modify, say you want to clone 20 enemies as a special power or something...GyroVorbis wrote:I recommend always passing (especially large) objects by reference.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.