Default parameter of a pointer

P

Patrick Kowalzick

Dear all,

Is the default parameter for t in the function foo guaranteed to be NULL in
the case below ?
(MSVC 7.1 and g++ implements it like that)

#include <iostream>

template <typename T>
void foo(const T & t = T())
{
std::cout << t << std::endl;
}

int main()
{
foo<void*>();
return 0;
}

Thanks,
Patrick
 
M

Mike Wahler

Patrick Kowalzick said:
Dear all,

Is the default parameter for t in the function foo guaranteed to be NULL in
the case below ?

Yes, if the passed argument is a pointer type.
(MSVC 7.1 and g++ implements it like that)

#include <iostream>

template <typename T>
void foo(const T & t = T())

-Mike
 
C

Chris Theis

Patrick Kowalzick said:
Dear all,

Is the default parameter for t in the function foo guaranteed to be NULL in
the case below ?

Yes

[SNIP]

Cheers
Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,178
Messages
2,570,955
Members
47,509
Latest member
Jack116

Latest Threads

Top