Re: Static class member error
On Wed, 7 May 2008 19:56:29 -0400, "Jeov? Almeida" <jeovaalmeida@yahoo.com>
wrote:
Hello Doug,
You said
The second parameter must be a const reference or simply a CString,
because it's illegal to bind a temporary to a non-const reference.
The second parameter is an output parameter, that is, if some error occurs
during the processing I can get the error message and log it, if I want. If
I make it a const reference, when I assign a value the strErrorMsg, I get
the error:
C2678: binary '=' : no operator found which takes a left-hand operand of
type 'const CString' (or there is no acceptable
Right, you can't assign to an object through a const reference, unless the
class is very, very weird and defines a const operator=.
I didn't realize it was an out parameter. What I said about binding a
temporary to a non-const reference is correct, and you shouldn't use a
default argument here. (Please ignore the fact that it works. <g> Try
compiling with /Za and you'll find that it doesn't.) It would be better to
stop using the default argument and split the function into two functions,
e.g.
static CString Get(LPCTSTR strURL)
{
CString x;
return Get(strURL, x);
}
static CString Get(LPCTSTR strURL, CString& strErrorMsg);
How do you distinguish an error return from a non-error return? If you
throw an exception, you can include an error message in the exception
object, and then you won't need the strErrorMsg parameter.
--
Doug Harrison
Visual C++ MVP