I know it may be badly encapsulated but I am no expert in Object oriented programming |
Which is why I brought it up. How will you learn if no one ever tells you ;P
I just use classes the way it best helps in doing my task in hand. |
That's the thing. You weren't doing that. That's kind of my point.
Ideally a class should be self contained and impossible to misuse. Your Triangle class would have to be used
a very specific way or else you will have all sorts of really bad problems (bad pointers, heap corruption, memory leaks, etc)
It may seem like no big deal now, but when your class is "open" like this.... when the entire program is responsible for taking care of Triangle (instead of Triangle just taking care of itself)... it's inevitable that you'll slip up, and have a program-killing bug. And since you give responsibility for Triangle to the entire program, it makes it
extremely difficult to find and correct the source of the bug.
The whole point of OOP is to split up tasks into smaller parts.
It makes no difference if the 'index' lement in the Triangle class is out of place! :) |
You may think that now... but you're wrong.
I doubt it really matters terribly if this is just some small test project you're throwing together, but I'd still argue it's bad practice.
Anyway, thanks for the advice but I plan to use memcpy |
Why?
You really shouldn't. std::copy is better and just as easy to use.
So what would be your suggestion, to make a copy of the above Triangle class?
|
same thing as last time:
1) don't have vertex pointers -- instead just have a 3 element array of verteces
2) use std::copy