public string getUser(const UserID& pUserID,const string& pName)
{
string musername;
//UserID is a class
//Here ia m doing some opertation to reterive user.
return musername;
}
Void Test()
{
string mUsername=getUser(NULL,pName);
//Error-passing NULL used for non-pointer converting 1 of `UserId::UserId(const long int&)'
}
So my question is how can i pass "NULL" class type object as funtion paramter .
Thanks,
Ashok
For reference variable they must always point to "something" unlike pointer. So you cannot pass in NULL instead. Maybe you can try temporaries instead.
I make some assumption. I assume UserID has a default constructor that take no arguments.
Just to note, reference variable is good. You don't have to check if the variable is NULL in your code unlike pointer variable. So for all new C++ code, use reference variable if possible. Use pointer variable for legacy C++ code maintenance or simply you like to see those * floating around in your code :)