Advertisement

09.17.2007 at 07:24AM PDT, ID: 22833238
[x]
Attachment Details

error C2664 can't convert const char [40] to char *

Asked by Bengal_Tiger in C++ Programming Language, Microsoft Visual C++.Net

Tags: char, convert, const, error, c2664

I am having trouble resolving the issue in the following code:

typedef struct _symbol_key
{
      // constructor
      _symbol_key( const char *pszSym )
      {
            if ( pszSym )
                  strncpy( szSym, pszSym, sizeof(szSym));
            else
                  szSym[0] = 0;
      }

      // overload the less than operator
      bool operator < ( const _symbol_key &key ) const
      {
            int iRet = strcmp( szSym, key.szSym );
            return (iRet < 0);
      }

      operator size_t() const
      {
            return hash_compare( szSym );    // error on this line...
      }

      unsigned long  hash_compare(char *str) const
      {
            unsigned long hash = 5381;
            int c;

            while (c = *str++)
                  hash = ((hash << 5) + hash) + c; /* hash * 33 + c */

            return hash;
      }

      char szSym[40];
} SYMBOL_KEY;



error C2664: 'mcapi::_symbol_key::hash_compare' : cannot convert parameter 1 from 'const char [40]' to 'char *'Start Free Trial
 
Loading Advertisement...
 
[+][-]09.17.2007 at 07:30AM PDT, ID: 19905200

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.17.2007 at 07:31AM PDT, ID: 19905206

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: C++ Programming Language, Microsoft Visual C++.Net
Tags: char, convert, const, error, c2664
Sign Up Now!
Solution Provided By: Infinity08
Participating Experts: 1
Solution Grade: A
 
 
[+][-]09.17.2007 at 08:51AM PDT, ID: 19905889

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628