no match for operator << ??

This is a discussion on no match for operator << ?? within the C++ Programming forums, part of the General Programming Boards category; I posted the wrong code before sorry i was missing a #include <fstream> i am a bit sleepy now but ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    27

    no match for operator << ??

    I posted the wrong code before sorry i was missing a #include <fstream>
    i am a bit sleepy now but i gotta hand in the program tomorrow and the only thing left was splitting the files !

    i get this error the first time i try to use the overloaded <<:
    main.cpp: In function ‘int main(int, char**)’:
    main.cpp:550: error: no match for ‘operator<<’ in ‘std::cout << fifolist

    << is overloaded to print the list ..

    fifo.h code is :
    Code:
     
    class fifo{
    
    //Other prototypes in the middle
    
        ostream& operator<<(ostream&);
    };
    and fifo.cpp :

    Code:
    ostream& operator<<(ostream &ons, fifo &object)
    {
        vector <double>:: iterator theiterator;
    
        if (object.list_size()==0){
    	cout<<"I fifo list einai keni!";
        }
        else
    	cout<<endl<<"Fifo List  :";
        for(theiterator=object.list_begin();theiterator!=object.list_end();theiterator++)
    	cout<<"  "<<*theiterator;
        cout<<endl;
    }
    Before i splitted the files i wasn't getting any errors.. Btw is there a tutorial online for splitting files with overloading >> or << ?
    Last edited by neoragexxx; 05-01-2006 at 05:14 PM.

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Did you include the appropriate stream header file in the file that this code came from?
    You're only born perfect.

  3. #3
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    for some reason, ye' code does not recognize the <iostream> library, which contains the functional implementation for the overloaded << insertion operator.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    27
    post edited and the includes are fine !

  5. #5
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Did you include a prototype for your << operator in a header file:
    Code:
    //probably in fifo.h
    ostream& operator<<(ostream &ons, fifo &object);
    "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

  6. #6
    Registered User
    Join Date
    Apr 2006
    Posts
    27
    i must get some rest... the one in the class isn't really the prototype..
    I just realized that .. so i must include the real prototype outside the class.

    thanks m8, it's just that my head is not working properly now and i didn't get it ..
    Last edited by neoragexxx; 05-01-2006 at 06:00 PM.

  7. #7
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    There's a difference between these two:
    Code:
    class Foo
    {
    public:
    ostream& operator<<(ostream&);
    friend ostream& operator<<(ostream &ons, fifo &object);
    };
    The first you would use like this (and it doesn't really make sense):
    Code:
    foo myFoo;
    myFoo<<std::cout;
    The second is what you want, or actually in this case it doesn't look like it needs to even be a member function, so just put the prototype outside your class.

    Edit: I meant to say, it doesn't need to be a friend function.
    "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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 03-30-2009, 07:37 PM
  2. no match for 'operator>>'
    By Taka in forum C++ Programming
    Replies: 3
    Last Post: 03-30-2009, 01:17 AM
  3. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 11:53 AM
  4. 2 array match
    By ajastru2000 in forum C++ Programming
    Replies: 5
    Last Post: 07-18-2003, 08:58 AM
  5. How do I match 2 files to print data.
    By sketchit in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 11-12-2001, 05:45 PM

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