Is it possible to assign null value as the default value for a default parameter

consider the following prototype

void function_name(std::string str1 , std::string str2="karthick");


Now, will i be able to assign a null value to the string as the default parameter. The compiler does not permit me when i use the following prototype

void function_name(std::string str1 , std::string str2=0);

So, is there anyway to assign null value as default value? if so, why does compiler throw an error for the above prototype!?
Try setting the default value to "".

-Albatross
That can be done. But i am think to get a null value to it. So that will force someone who implements the function to assign some value before he/she uses it.


I think I asked a dumb question.

There is no way of assigning a null value to the int. Same way i think there is no way to assign a null value to a string.

To serve the above purpose, I think I could do something like this

void function_name(std::string str1, std::string *str=0);

correct me if am wrong in the stuff below..

I forgot the basic stuff that
string str; => string str("");





Topic archived. No new replies allowed.