Jun 7, 2010 at 4:17am UTC
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!?
Jun 7, 2010 at 4:18am UTC
Try setting the default value to "".
-Albatross
Jun 7, 2010 at 4:22am UTC
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.
Jun 7, 2010 at 5:35am UTC
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("");