Thread: cannot convert parameter 2 from 'char *' to 'const char &'

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    26

    cannot convert parameter 2 from 'char *' to 'const char &'

    Okay, this error is rather annoying, as I can not progress with my program without resolving it.

    It is an e-mail checker, and this part is extracting the domains (we previously did it with arrays) using a user-defined template vector class (using char as the type). As of now I'm completely stumped since most of the code was pseudo code from my professor, so I know I'm at least on the right track...

    Code:
    class EmailDomain
    {
       public:
          EmailDomain()
          {
              Name = DynamicString::DynamicString();
              SubdomainCount = 0;
          }
       
       public:
          DynamicString Name;
    
          Vector<char> Subdomain;
          //EmailSubdomain Subdomain[MAX_SUBDOMAINS];
          int SubdomainCount;
          EmailTld Tld;
    
       public:
          bool Parse();
          bool IsValid();
    };
    Code:
    // Extract subdomains
       do
       {
          int nextPosition = Name.IndexOf('.', startPosition);
          Subdomain.BoostCapacity(1);
          if ( nextPosition != -1 )
          {
              Name.Copy(Name.Buffer, Subdomain.Buffer, startPosition + 1, nextPosition - startPosition);
              Subdomain.InsertAt( Subdomain.Size, Subdomain.Buffer );
          }
          else
              Name.Copy(Name.Buffer, Tld.Name.Buffer, startPosition + 1, Name.Size);
          startPosition = nextPosition + 1;
    
       } while ( startPosition != 0 );
    Buffer is of type T* (so in this case....char*) in the vector class

    And here is the InsertAt function from the Vector class

    Code:
    void InsertAt(int index, const T& value)
        {
            
            if ( index > Size || index < 0 )
                throw "Vector::InserAt() index out of range";
    
            // Exceeding current capacity?
            BoostCapacity(1);
    
            // Make room for the new intacter
            MoveBy(index, 1);
            Size++;
    
            // Set the value
            Buffer[index] = value;
        }
    The error occurs on the line that is bold, italicized and underlined

    If you need anything else, just ask me. Thanks!

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Is InsertAt a member function? I assume it must be from the way you call it, but the definition is that of a non-member (and non-template). I would expect it to be:
    Code:
    template <class T>
    void Vector<T>::InsertAt(int index, const T& value)
    {
      //...
    }
    If that were the case, assuming T = char, then you're trying to pass a pointer to char to a function that expects a reference to char.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    26
    Yes, it's a member of the Vector class.


    The only reason why the function header doesn't look right is because it's currently defined in the Vector.h class...I haven't created the .cpp implementation file for it yet..I want to get it working first

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You probably want Subdomains to be a Vector<string> or something similar, since a char holds only a single character.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Including The Right DLLs
    By bumfluff in forum Game Programming
    Replies: 8
    Last Post: 12-28-2006, 03:32 AM
  4. Display Lists (OpenGL)
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 06-05-2005, 12:11 PM
  5. AnsiString versus char *
    By Zahl in forum C++ Programming
    Replies: 35
    Last Post: 10-16-2002, 08:38 PM