How can i Pass parameter "NULLL" as class object.

Hi,
I have a function as follows.

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
Last edited on
const UserID& pUserID


For reference variable they must always point to "something" unlike pointer. So you cannot pass in NULL instead. Maybe you can try temporaries instead.

E.g
string mUsername=getUser(UserID(),pName);
Thanks buddy. Solution worked for me.
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 :)
Topic archived. No new replies allowed.