I have << overloaded to write to a file, however I get an error when I try to use it in main. I tried calling the actual write method. Is the SpareTable that operator that is failing. I already checked the .h and .cpp parameters and that all my #includes where in place. Thanks for the help

static ofstream lout ("lists.txt");
srand (2231);
SkipList list;
int i, compares;
try{
    for (int n = 1; n <= 5; n++){
         i = rand();
         compares = list.add (i);
         updateStats (n, 5, compares);
         
        if (compares == -1) {
            cout << "memory overflow!\n";
            exit (1);
            }
       
        lout << "** add #" << setw(5) << n << ": " << setw(5) << i << " **\n"; //<< list; // this gives error
        list.write(lout); // yet this works fine
void SkipList::write (ofstream& outfile)const {
        SkipListNode* current = heads[0];
 
        while (current != NULL){
            current -> write (outfile);
            current = current -> getNext(0);
        }
        outfile <<"\n";
    }
    
    ofstream& operator << (ofstream& outfile, const SkipList& list){
        list.write(outfile);
        return outfile;
    }
void SkipListNode::write (ofstream& outfile) const{

        outfile << value << " ";
        for (int i = 0; i < getNumberOfLinks(); i++){
            if (getNext(i)){
                outfile << "( " << getNext(i) -> getValue() << ") ";
            }
            else {
                outfile << "( / )";
            }
        }
        outfile << endl;
    }

    ofstream& operator << (const SkipListNode& node, ofstream& outfile){
        node.write(outfile);
        return outfile;
    }
/*******master.h*********/
#ifndef MASTER_H
#define MASTER_H
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::ostream;
using std::ios;
#include <iomanip>
using std::setw;
using std::setprecision;
#include <fstream>
using std::ofstream;
#include <ctime>
#include <cstdlib>
#include <cmath>
#include "Node.h"
#include "LinkedNode.h"
#include "ArrayBoundsException.h"
#include "SkipListNode.h"
#include "SkipList.h"
#endif

What is the message with the error that it is giving you?

What is the message with the error that it is giving you?

I'm getting the 40 paragraph long error message saying it almost matches this method on this method etc.... well here i'll just paste it

main.cpp:33: error: no match for 'operator<<' in 'std::operator<< [with _Traits 
= std::char_traits<char>](((std::basic_ostream<char, std::char_traits<char> >&)(
(std::basic_ostream<char, std::char_traits<char> >*)((std::basic_ostream<char, s
td::char_traits<char> >*)std::operator<< [with _CharT = char, _Traits = std::cha
r_traits<char>](((std::basic_ostream<char, std::char_traits<char> >&)((std::basi
c_ostream<char, std::char_traits<char> >*)std::operator<< [with _Traits = std::c
har_traits<char>](((std::basic_ostream<char, std::char_traits<char> >&)((std::ba
sic_ostream<char, std::char_traits<char> >*)((std::basic_ostream<char, std::char
_traits<char> >*)std::operator<< [with _CharT = char, _Traits = std::char_traits
<char>](((std::basic_ostream<char, std::char_traits<char> >&)((std::basic_ostrea
m<char, std::char_traits<char> >*)std::operator<< [with _Traits = std::char_trai
ts<char>](((std::basic_ostream<char, std::char_traits<char> >&)(& std::cout)), (
(const char*)"** add #")))), std::setw(5)))->std::basic_ostream<_CharT, _Traits>
::operator<< [with _CharT = char, _Traits = std::char_traits<char>](n))), ((cons
t char*)": ")))), std::setw(5)))->std::basic_ostream<_CharT, _Traits>::operator<
< [with _CharT = char, _Traits = std::char_traits<char>](i))), ((const char*)" *
*\012")) << list'
/usr/include/c++/4.2.1/ostream:112: note: candidates are: std::basic_ostream<_Ch
arT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostrea
m<_CharT, _Traits>& (*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = ch
ar, _Traits = std::char_traits<char>]
/usr/include/c++/4.2.1/ostream:121: note:                 std::basic_ostream<_Ch
arT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_C
harT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Tra
its = std::char_traits<char>]
/usr/include/c++/4.2.1/ostream:131: note:                 std::basic_ostream<_Ch
arT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*
)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.2.1/ostream:169: note:                 std::basic_ostream<_Ch
arT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _
CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.2.1/ostream:173: note:                 std::basic_ostream<_Ch
arT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int
) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.2.1/ostream:177: note:                 std::basic_ostream<_Ch
arT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _Char
T = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.2.1/bits/ostream.tcc:92: note:                 std::basic_ost
ream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int
) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.2.1/ostream:184: note:                 std::basic_ostream<_Ch
arT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned in
t) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.2.1/bits/ostream.tcc:106: note:                 std::basic_os
tream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [wi
th _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.2.1/ostream:195: note:                 std::basic_ostream<_Ch
arT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [wi
th _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.2.1/ostream:204: note:                 std::basic_ostream<_Ch
arT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [w
ith _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.2.1/ostream:208: note:                 std::basic_ostream<_Ch
arT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigne
d int) [with _CharT = char, _Traits = std::char_traits<char>] ... you get the idea

I also thought it could have been an inheritance problem but, I just finished another program in which I inherited from the same files as I am inheriting from in this program

Ah yes I know that one well. Unfortunately it doesn't give me too much to go on...it was worth a try.

On line 15 of your second-to-last box is there some reason why you have the parameters flipped around?

lol how did i not notice that ..... wait why didn't my compiler notice that? Thanks for the help!!! Nothing more irritating then breezing through a homework assignment just to have a typo to stop you in your tracks. Thanks again

Not a problem. Good luck with it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.