problem writing a string container class

This is a discussion on problem writing a string container class within the C++ Programming forums, part of the General Programming Boards category; Im having trouble implementing a 'const char *' cast operator along with an indexing operator ('[]'). Everytime I try to ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    552

    problem writing a string container class

    Im having trouble implementing a 'const char *' cast operator along with an indexing operator ('[]'). Everytime I try to compile VC6 gives me a 'two overloads with similar conversions' error.

    I'd post code, but I'm ever-so certain its not a code problem. Has anyone encountered a problem like this? Is there any way to suppress the built-in operators, or maybe force the compiler to choose one over the other?

  2. #2
    Registered User Mario's Avatar
    Join Date
    May 2002
    Posts
    317
    It would be a good idea to post the code... at least the prototypes for the operator overloading functions. According to VC you are breaking the conversion rules for overloading functions and generating ambiguous calls.
    Regards,
    Mario Figueiredo
    Using Borland C++ Builder 5

    Read the Tao of Programming
    This advise was brought to you by the Comitee for a Service Packless World

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    Code:
    // .h
    operator const char *() const { return myCString; }
    char & operator[] (unsigned ind) { return myCString[ind]; }
    .
    .
    .
    // .cpp
    String str = "ABC";
    str[0] = 'X';  // error

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM
  4. Another overloading "<<" problem
    By alphaoide in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2003, 10:32 AM
  5. Replies: 3
    Last Post: 12-03-2001, 12:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21