Click here to Skip to main content
15,887,350 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Event objects VS Global variables Pin
Stephen Hewitt18-Jun-15 6:41
Stephen Hewitt18-Jun-15 6:41 
QuestionRe: Event objects VS Global variables Pin
David Crow18-Jun-15 9:15
David Crow18-Jun-15 9:15 
AnswerRe: Event objects VS Global variables Pin
Richard Andrew x6418-Jun-15 9:48
professionalRichard Andrew x6418-Jun-15 9:48 
AnswerRe: Event objects VS Global variables Pin
Stephen Hewitt18-Jun-15 15:42
Stephen Hewitt18-Jun-15 15:42 
AnswerRe: Event objects VS Global variables Pin
Frankie-C19-Jun-15 6:09
Frankie-C19-Jun-15 6:09 
Question[C] possible OOP approach Pin
lukeer17-Jun-15 21:17
lukeer17-Jun-15 21:17 
AnswerRe: [C] possible OOP approach Pin
CPallini17-Jun-15 21:25
mveCPallini17-Jun-15 21:25 
AnswerRe: [C] possible OOP approach Pin
Stefan_Lang18-Jun-15 20:36
Stefan_Lang18-Jun-15 20: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 12:08
cth02721-Jun-15 12:08 
QuestionSuggestions on real-time video display with drawing Pin
Kiran Satish17-Jun-15 6:08
Kiran Satish17-Jun-15 6:08 
AnswerRe: Suggestions on real-time video display with drawing Pin
CPallini17-Jun-15 21:06
mveCPallini17-Jun-15 21:06 
GeneralRe: Suggestions on real-time video display with drawing Pin
Kiran Satish23-Jun-15 9:39
Kiran Satish23-Jun-15 9:39 
GeneralRe: Suggestions on real-time video display with drawing Pin
DEmberton26-Jun-15 3:44
DEmberton26-Jun-15 3:44 
QuestionCString.Format anomaly Pin
ForNow17-Jun-15 3:02
ForNow17-Jun-15 3:02 
AnswerRe: CString.Format anomaly Pin
Richard MacCutchan17-Jun-15 3:13
mveRichard MacCutchan17-Jun-15 3:13 
GeneralRe: CString.Format anomaly Pin
ForNow17-Jun-15 7:48
ForNow17-Jun-15 7:48 
GeneralRe: CString.Format anomaly Pin
Richard MacCutchan17-Jun-15 8:07
mveRichard MacCutchan17-Jun-15 8:07 
GeneralRe: CString.Format anomaly Pin
ForNow17-Jun-15 8:26
ForNow17-Jun-15 8:26 
AnswerRe: CString.Format anomaly Pin
Jochen Arndt17-Jun-15 3:27
professionalJochen Arndt17-Jun-15 3:27 
GeneralRe: CString.Format anomaly Pin
ForNow17-Jun-15 7:46
ForNow17-Jun-15 7:46 
GeneralRe: CString.Format anomaly Pin
jeron117-Jun-15 8:00
jeron117-Jun-15 8:00 
GeneralRe: CString.Format anomaly Pin
ForNow17-Jun-15 8:11
ForNow17-Jun-15 8:11 
GeneralRe: CString.Format anomaly Pin
jeron117-Jun-15 8:19
jeron117-Jun-15 8:19 
QuestionMultithread c Windows Pin
mosine16-Jun-15 2:22
mosine16-Jun-15 2:22 
AnswerRe: Multithread c Windows Pin
Jochen Arndt16-Jun-15 2:33
professionalJochen Arndt16-Jun-15 2: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.