Click here to Skip to main content
14,362,963 members

C / C++ / MFC

 
AnswerRe: Event objects VS Global variables Pin
Stephen Hewitt18-Jun-15 7:41
memberStephen Hewitt18-Jun-15 7:41 
QuestionRe: Event objects VS Global variables Pin
David Crow18-Jun-15 10:15
memberDavid Crow18-Jun-15 10:15 
AnswerRe: Event objects VS Global variables Pin
Richard Andrew x6418-Jun-15 10:48
professionalRichard Andrew x6418-Jun-15 10:48 
AnswerRe: Event objects VS Global variables Pin
Stephen Hewitt18-Jun-15 16:42
memberStephen Hewitt18-Jun-15 16:42 
AnswerRe: Event objects VS Global variables Pin
Frankie-C19-Jun-15 7:09
memberFrankie-C19-Jun-15 7:09 
Question[C] possible OOP approach Pin
lukeer17-Jun-15 22:17
memberlukeer17-Jun-15 22:17 
AnswerRe: [C] possible OOP approach Pin
CPallini17-Jun-15 22:25
mveCPallini17-Jun-15 22:25 
AnswerRe: [C] possible OOP approach Pin
Stefan_Lang18-Jun-15 21:36
memberStefan_Lang18-Jun-15 21:36 
I've had a quick look, and IMHO the code is severely lacking. Most importantly, the classes are often passed by value instead of by reference. Therefore, every time a hard copy is created. Apart from potential issues regarding performance and memory for more complex object instances, this also means that any code attempting to modify an object using these calls will not work!

Example: the destructor code passes the object that is to be destructed by value!? This will allow you to clean up resources such as pointers to allocated secondary objects, but if you're managing something more complex, such as a database connection or file handle, you're going to have severe issues, if you can properly clean this up at all!

Similarly, the sound() functions create local hard copies of the object that in this case is correctly being passed by reference. Why the author did this is beyond me - it generates needless overhead and ensures that you can not modify the original object. Most importantly, modifying the local copy will not change the behavior of the referenced object that was passed to the function, i. e. the effect of these functions is zero!

Also the example main function doesn't show inheritance at all, because it always directly calls the sound() function on the class interface it is created as (e. g. calling dog.sound()). The only way to prove there is something like virtual inheritance at play is to store the cat and dog objects as animal references, and call the sound() function via the animal class interface. Without actually trying, I predict however, it won't work, because the "derived" sound() functions won't be called, and, therefore, the super class won't adjust it's behaviour.

Always referencing class objects through pointers would go a long way to fix the code and get it towards what the author originally intended. But that still wouldn't introduce polymorphism or encapsulation.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

AnswerRe: [C] possible OOP approach Pin
cth02721-Jun-15 13:08
membercth02721-Jun-15 13:08 
QuestionSuggestions on real-time video display with drawing Pin
Kiran Satish17-Jun-15 7:08
memberKiran Satish17-Jun-15 7:08 
AnswerRe: Suggestions on real-time video display with drawing Pin
CPallini17-Jun-15 22:06
mveCPallini17-Jun-15 22:06 
GeneralRe: Suggestions on real-time video display with drawing Pin
Kiran Satish23-Jun-15 10:39
memberKiran Satish23-Jun-15 10:39 
GeneralRe: Suggestions on real-time video display with drawing Pin
DEmberton26-Jun-15 4:44
memberDEmberton26-Jun-15 4:44 
QuestionCString.Format anomaly Pin
ForNow17-Jun-15 4:02
memberForNow17-Jun-15 4:02 
AnswerRe: CString.Format anomaly Pin
Richard MacCutchan17-Jun-15 4:13
protectorRichard MacCutchan17-Jun-15 4:13 
GeneralRe: CString.Format anomaly Pin
ForNow17-Jun-15 8:48
memberForNow17-Jun-15 8:48 
GeneralRe: CString.Format anomaly Pin
Richard MacCutchan17-Jun-15 9:07
protectorRichard MacCutchan17-Jun-15 9:07 
GeneralRe: CString.Format anomaly Pin
ForNow17-Jun-15 9:26
memberForNow17-Jun-15 9:26 
AnswerRe: CString.Format anomaly Pin
Jochen Arndt17-Jun-15 4:27
mveJochen Arndt17-Jun-15 4:27 
GeneralRe: CString.Format anomaly Pin
ForNow17-Jun-15 8:46
memberForNow17-Jun-15 8:46 
GeneralRe: CString.Format anomaly Pin
jeron117-Jun-15 9:00
memberjeron117-Jun-15 9:00 
GeneralRe: CString.Format anomaly Pin
ForNow17-Jun-15 9:11
memberForNow17-Jun-15 9:11 
GeneralRe: CString.Format anomaly Pin
jeron117-Jun-15 9:19
memberjeron117-Jun-15 9:19 
QuestionMultithread c Windows Pin
mosine16-Jun-15 3:22
membermosine16-Jun-15 3:22 
AnswerRe: Multithread c Windows Pin
Jochen Arndt16-Jun-15 3:33
mveJochen Arndt16-Jun-15 3:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.