Afficher un message
Vieux 16/10/2007, 00h01   #6
Erik Wikström
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Why use object pointers rather than objects?

On 2007-10-16 00:46, Krishna wrote:
> On Oct 15, 2:14 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
>> krishna.kishore.0...@gmail.com wrote:
>> > Why are always object pointers used? (i.e., ObjectType *objPointer)

>>
>> Always? I don't always use them. In fact, I seldom use them.
>> This is a very typical example of where I don't use them:
>>
>> std::string s = "hello";
>>
>> No pointer there.
>>
>> > one advantage I see is passing them across methods, but is this purely
>> > presentation issue (use 'objPointer' rather than '&obj') or are there
>> > some performance affects?

>>
>> If you pass an object by value then a copy will most probably be made,
>> which will often be less efficient than passing by reference or by
>> pointer. Also there's the slicing problem if inheritance is involved.

>
> Hi Guys,
> Thanks for the replies. When I was punching 'always' I was stuck in
> the world of GUI, I see pointers being used for GUI objects, 'always'


That would probably be because GUI classes often makes heavy use of
polymorphism, (most graphical elements inherit from a base widget (or
whatever) class, and often implements a number of interfaces).

--
Erik Wikström
  Réponse avec citation
 
Page generated in 0,06188 seconds with 9 queries