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

  1. #1
    Registered User
    Join Date
    Sep 2006

    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...

    class EmailDomain
              Name = DynamicString::DynamicString();
              SubdomainCount = 0;
          DynamicString Name;
          Vector<char> Subdomain;
          //EmailSubdomain Subdomain[MAX_SUBDOMAINS];
          int SubdomainCount;
          EmailTld Tld;
          bool Parse();
          bool IsValid();
    // Extract subdomains
          int nextPosition = Name.IndexOf('.', startPosition);
          if ( nextPosition != -1 )
              Name.Copy(Name.Buffer, Subdomain.Buffer, startPosition + 1, nextPosition - startPosition);
              Subdomain.InsertAt( Subdomain.Size, Subdomain.Buffer );
              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

    void InsertAt(int index, const T& value)
            if ( index > Size || index < 0 )
                throw "Vector::InserAt() index out of range";
            // Exceeding current capacity?
            // Make room for the new intacter
            MoveBy(index, 1);
            // 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
    Seattle, WA
    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:
    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."

  3. #3
    Registered User
    Join Date
    Sep 2006
    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
    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