473,386 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Default parameter of a pointer

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
Jul 22 '05 #1
2 1213

"Patrick Kowalzick" <ko*******@gmx.net> wrote in message
news:3F****************@nntpserver.swip.net...
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
Jul 22 '05 #2

"Patrick Kowalzick" <ko*******@gmx.net> wrote in message
news:3F****************@nntpserver.swip.net...
Dear all,

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


Yes

[SNIP]

Cheers
Chris
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: earl | last post by:
class temp { public: temp(); foo(char, char, char*); private: char matrix; }; temp::foo(char p, char o, char m = matrix )
3
by: Ed Morton | last post by:
Anyone know why "const" isn't the default for function parameters? I almost never see code where function parameters are modified intentionally (and when I do, I usually think copying the value to...
16
by: hzmonte | last post by:
Correct me if I am wrong, declaring formal parameters of functions as const, if they should not be/is not changed, has 2 benefits; 1. It tells the program that calls this function that the...
5
by: asianmuscle | last post by:
I am trying to learn RAII and some template techniques by writer a smarter pointer class to manage the resource management. Since I find that a lot of the resource management is kinda the same, I...
3
by: Gary Wessle | last post by:
I have a method with the last arguments having defaults like this void filing(long, double, const myType& r_mo=NULL, const herType& r_tr=NULL); is that acceptable, if not how is it done?...
12
by: claudiu | last post by:
Hi, I'll go straight to the first question. Why does the code below compile? void f(int i = 0); int main() { (&f)();
9
by: George2 | last post by:
Hello everyone, I am wondering the default implementation of assignment operator (e.g. when we do not implement assignment operator in user defined class, what will be returned? temporary...
6
by: Tim Frink | last post by:
Hi, how can I set default values to template parameters? I've this code: class A { template<typename T> void foo( string = "", T* = 0, bool (T::*func)(void) = 0 );
2
by: Clyde | last post by:
Hi, what i'm trying to do is: /////////////// Code Start template <class TType, int* p = 0> class Template { public:
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.