Sebi
Sebi

Reputation: 4522

Template class method syntax

In the following example:

template<class Foo>
struct FooBar 
{
   FooBar(Foo *pObj = 0) : pFoo_(pObj) {}
};

what does "*pObj = 0" mean?

Upvotes: 0

Views: 107

Answers (1)

Linuxios
Linuxios

Reputation: 35793

It means that the default value of pObj, if the caller doesn't provide one, is 0. In this particular case, it would have been better form to use NULL (which is usually a macro of 0). There are now two ways of calling it:

FooBar fb = FooBar(); //pObj is NULL
FooBar fb2 = FooBar(someFoo); //pObj is someFoo

Upvotes: 2

Related Questions