Can anyone lead me in the right direction to get this to work???

my << overload compiles fine...

ofstream& operator<<(ofstream& ofs, const GameBoard& b) //overloaded ofstream operator to save board & piece
{
    for (int row=0; row < b.size; row++) {
        for (int col; col < b.size; col++) {
            ofs << b.pieces[row][col].pType;
        }
    }
    return ofs;
};

I get an error trying to use it...

void GameBoard::PrintGametoFile()       

{
    ofstream outFile;
    outFile << *this;
}

error - error C2593: 'operator <<' is ambiguous

This may be an issue.

for (int col; col < b.size; col++) {

Initialize col.

As far as the other error, let me try to find the rest of your code. (And functions don't end in a semicolon.)

[edit]The advice here is to have it the other way around -- to have the "operator<< call that printOn() method".

Is there a way to fix this so I don't have to create a new function? I attached my code to look at, if that helps...

It looks to me like there are other things to fix first.

GameBoard& GameBoard::operator=(const GameBoard& right)
{
    for (int i = 0; i < size; ++i) {             // destructor if existing
        delete[] pieces[i];
    }
    delete[] pieces;

    const int size = right.size;
    playType = right.playType;

    maxMoves = size*size;
    pieces = new GamePiece*[size];
    for (i=0; i<size; i++)
    {
        pieces[i]=new GamePiece[size];
    } return *this;
}

Dead giveaway of MSVC6 -- use of broken scoping rules. Declare i above the first for loop.

for (int col; col < b.size; col++) {

You still have a lot of these errors -- using uninitialized counters.

And I get quite a few of these:

Error E2247 testpp.cpp 364: 'GamePiece::pType' is not accessible in function GameBoard::CheckForWinner(GamePiece &,GamePiece &)
Error E2228 testpp.cpp 364: Too many error or warning messages in function GameBoard::CheckForWinner(GamePiece &,GamePiece &)

void GameBoard::PrintGametoFile()       
{
    ofstream outFile;
    outFile << *this;
}

Just where do you expect this "output" to go?

I'm sure there are a lot of errors ;) I haven't written anything for about 3-4 years and that was just the intro to c++ class...

I'm really struggling with the overloaded operators << and >> and how they are actually called by the other functions...

Is this sufficient for the ofstream??

{
	ofstream outFile;
	outFile.open("tttgame.txt");
	outFile << *this;
}

also, what compiler are you using?

Is this sufficient for the ofstream??

{
	ofstream outFile;
	outFile.open("tttgame.txt");
	outFile << *this;
}

Looks okay to me.

also, what compiler are you using?

BC55

what would cause this error??

error C2593: 'operator <<' is ambiguous

using the code above with the ofstream overload??

mt

Perhaps.

Sorry, I'm just not seeing it. I made a project in MSVC6 with these two files and its only complaint was this.

C:\Test\GAMEBOARD.CPP(133) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class GameBoard *' (or there is no acceptable conversion)

Simple fix:

inFile >> *board;

I've gotten that one, too... For some reason, that one's disappeared for me now... Not sure what's going on... :o

Thanks for all of the suggestions.. I really appreciate it!

mt

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.