Re: Static class member error
On Wed, 7 May 2008 17:36:55 -0400, "Jeov? Almeida" <jeovaalmeida@yahoo.com>
wrote:
Hello,
I'm (trying to) implementing an intenet helper static class for GET and POST
calls:
Using a namespace instead of a class may be a better bet.
CString result = CHttpClient::Get("www.servername.com")
The problem is I'm using wininet and when I call
CInternetSession::GetHttpConnection(szServerUrl), the compiler gives me the
error
C2352: 'CInternetSession::GetHttpConnection' : illegal call of non-static
member
How can I achieve the same result (that is call CHttpClient::Get()
statically) using wininet, bypassing this error
To call a non-static member function, you need an instance of the class, so
you'll have to create a CInternetSession object.
As an additional info, the member declaration in the .h file is
static CString Get(LPCTSTR strURL, CString& strErrorMsg=CString() );
This seems familiar, and if so, it's not what I showed you. 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. (Yes, VC still allows
it for compatibility reasons.) Also, it's more efficient to implement this
as two functions, because then you don't construct and destroy a temporary
CString at each call site.
--
Doug Harrison
Visual C++ MVP