Click here to Skip to main content

Welcome to the Lounge

   

For lazing about and discussing anything in a software developer's life that takes your fancy.
The Lounge is rated PG. If you're about to post something you wouldn't want your kid sister to read then don't post it. No flame wars, no abusive conduct and please don't post ads.

Technical discussions are welcome, but if you need specific help please use the programming forums.


 
GeneralRe: USB Problems PinmemberKevin Marois6-Nov-12 6:31 
GeneralWhy I like C++ PinmemberCDP18026-Nov-12 5:20 
GeneralRe: Why I like C++ PinmemberAlbert Holguin6-Nov-12 5:40 
GeneralRe: Why I like C++ PinmemberMike Hankey6-Nov-12 6:25 
GeneralRe: Why I like C++ PinmemberJoe Woodbury6-Nov-12 6:52 
GeneralRe: Why I like C++ PinmemberCDP18026-Nov-12 8:27 
GeneralRe: Why I like C++ PinmemberMartin.Cheng6-Nov-12 20:35 
GeneralRe: Why I like C++ [modified] PinmemberCDP18027-Nov-12 0:06 
Martin.Cheng wrote:
Can somebody give some advises how to learn C++

Five steps:
 
1) Learn C, especially how to write functions. A C++ object's methods work very much like C functions. You will be able to use your experience with C here.
 
2) Learn about object orientation by understanding the concept. The way the concepts are implemented in C++ (or any other language) are secondary at the moment. Begin with understanding what an object actually is: A data structure with attached functions to allow safe manipulation of the data inside that structure.
 
3) Learn the difference between a class (the definition) and objects (individual instances of a class). That will lead you to learning about the basic lifecycle of an object. Allocation of memory and automatic execution of the constructor when you create a new object with 'new', and automatic execution of the destructor and freeing memory when you destroy an object with 'delete'. Despite their somewhat scary names, constructors and destructors are just functions which are called automatically when you create or destroy objects. It's very important that you learn to use them to initialize or clean up an object.
 
4) Learn to use encapsulation to divide up the internal state of an object and its external interface. Other objects can only access methods or member variables of an object which you have declared as 'public'. They get no access to the members you declare to be 'private'. This way you can limit how the object's state is altered from the outside and keep it valid at all times. Limitations and restrictions may sound like a bad thing, but in reality they are your best friend.
 
5) Learn how to use inheritance and how to design class hierarchies. It's a powerful instrument for writing type safe code and avoiding redundancy. It is also an instrument you have to learn to play well, because it can also quickly lead to bad design.
 
Speaking of bad design: C++ allows classes and functions to be 'friends' of other classes. That actually means breaking the encapsulation. Like feeling the need to use 'goto', it's a sign that you should rethink your design.

modified 7-Nov-12 8:30am.

GeneralRe: Why I like C++ PinmemberJohn Atten7-Nov-12 2:10 
GeneralRe: Why I like C++ PinmemberMartin.Cheng7-Nov-12 3:19 
GeneralRe: Why I like C++ PinmemberSeattleC++7-Nov-12 5:16 
GeneralRe: Why I like C++ PinmemberMartin.Cheng7-Nov-12 14:18 
GeneralRe: Why I like C++ PinmemberSeattleC++7-Nov-12 18:15 
GeneralRe: Why I like C++ PinmemberMartin.Cheng7-Nov-12 19:38 
GeneralRe: Why I like C++ Pinmemberjschell7-Nov-12 7:43 
GeneralRe: Why I like C++ PinmemberMartin.Cheng7-Nov-12 19:34 
GeneralRe: Why I like C++ PinmemberFabio Franco7-Nov-12 8:51 
GeneralRe: Why I like C++ PinmemberMartin.Cheng8-Nov-12 14:31 
GeneralRe: Why I like C++ PinmemberFabio Franco8-Nov-12 16:32 
GeneralRe: Why I like C++ PinmemberMartin.Cheng8-Nov-12 18:32 
GeneralRe: Why I like C++ PinmemberFabio Franco9-Nov-12 3:01 
GeneralRe: Why I like C++ PinmemberMartin.Cheng9-Nov-12 20:16 
GeneralRe: Why I like C++ PinmemberFabio Franco10-Nov-12 15:44 
GeneralRe: Why I like C++ PinmemberMartin.Cheng10-Nov-12 16:08 
GeneralRe: Why I like C++ PinmemberCDP18027-Nov-12 10:16 

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

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


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 28 Aug 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid