Thread: overloaded operator for type conversion error

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    19

    overloaded operator for type conversion error

    Here is what my operator looks like:
    Code:
    istring.hpp
    ---------------
    
    operator char*() const;
    Code:
    istring.cpp
    ---------------
    
    IString :: operator char*() const
    {
        return ((string*)buffer)->data(); 
    }

    here string is the regular STL string. I get the following error when I try to compile this:

    "/h/IString/istring.cpp", line 71.39: 1540-0258 (S) A return value of type "char *" cannot be initialized with an expression of type "const char *".
    make: 1254-004 The error code from the last command is 1.

    Any ideas?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Any ideas?
    The string type's data() member function returns a const qualified type. Instead of operator char *, why not use
    Code:
    operator const char*() const;
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  2. Simple vector class problem, please help
    By fidodidohk in forum C++ Programming
    Replies: 9
    Last Post: 03-30-2007, 09:13 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  5. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM