I\'m used to doing Java programming, where you never really have to think about pointers when programming. However, at the moment I\'m writing a program in C++. When making
Start by avoiding pointers.
Use them when:
Bar instance is actually managed by some other part of your program, whereas the Foo class just needs to be able to access it.Bar object (i.e., you want to create it after constructing Foo).Bar object may not exist at all; you would use null also in Java. However, check out boost::optional as well.Bar is actually a base class, and you need the instance to be polymorphic.In any of these cases (*), start by using a smart pointer, such as boost::shared_ptr. Otherwise, you are likely to forget to deallocate the memory, sooner or later. Once you know what you are doing, consider case-by-case what pointer type is best.
(*) any case – except, probably, the bullet regarding GUI widgets; in this case, your toolkit would most probably manage the resources for you as well