overloading extraction and insertion

This is a discussion on overloading extraction and insertion within the C++ Programming forums, part of the General Programming Boards category; I have written a field class that inherits from the string class, but I need to overload the << and ...

  1. #1
    Registered User brianptodd's Avatar
    Join Date
    Oct 2002
    Posts
    66

    overloading extraction and insertion

    I have written a field class that inherits from the string class, but I need to overload the << and >> operators to handle input/output to a file but I am having trouble with the implementation.

    Any help?
    "In theory, there is no difference between theory and practice. But, in practice, there is."
    - Jan L.A. van de Snepscheut

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Post what code you do have, and the errors you're getting.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    In addition to posting code, maybe you can reassure us that you've considered the fact that is generally considered a bad idea to use a class that has no virtual destructor (or any other virtual functions) as a base class. In this case, string was not designed to be inherited from through public derivation.

    If you have considered this, then okay, good luck.

    If not, then maybe you should consider a different solution. Or if you are interested maybe I or someone else here can explain the dangers of doing that in more detail.

  4. #4
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Yeah -- deriving from std::string == bad

    Perhaps you can create a new typedef with different parameters to std::basic_string, and then overload the functions you need.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Overloading fstream's << and >> operators
    By VirtualAce in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2007, 03:17 AM
  2. overload operator+ in format (z + obj2)
    By slrj in forum C++ Programming
    Replies: 18
    Last Post: 10-11-2006, 02:55 PM
  3. Overloading < or > operators
    By mouse163 in forum C++ Programming
    Replies: 3
    Last Post: 03-30-2003, 07:32 PM
  4. Overloading insertion and extraction problem
    By Curwa in forum C++ Programming
    Replies: 1
    Last Post: 01-15-2003, 08:20 PM

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