PDA

View Full Version : Probably trivial C++ error, but not for me.


WhatMeWorry
2005.06.13, 01:53 PM
This worked fine in CodeWarrior, so Xcode must be more rigorous. This same
compiler error is happening in many, many places and after 2 hours I'm stumped.

error: statement cannot resolve address of overloaded function

Here's just one specific method, but I use the general pattern repeatedly:

void Unit::displayShipIdsInHanger( Unit *u )
{
ofstream outFile( "HangerPlanes.txt", ios::app );

outFile << u->name << endl;
outFile << "unitId " << u->unitId << endl;

outFile.close;
}

The error dohickey (red stop sign?) is at the outFile.close line. I'm stumped.
The documentation of ofstream class just shows one declaration of close
and it is something like void close(), so how in the hell could it be overloaded
even if I wanted it to be, which I don't?

Thanks in advance.

TomorrowPlusX
2005.06.13, 02:26 PM
Did you forget the () on close?

"outfile.close" is the address of a method, and without assignment it's basically a no op. Whereas "outfile.close()" is the invocation.

WhatMeWorry
2005.06.13, 03:47 PM
Yes! Thank you very much. (Although Codewarrior was treating it
like a valid invocation, because it was creating output).

TomorrowPlusX
2005.06.13, 05:01 PM
Actually, it was *not*.... the destructor was implicitly calling close() -- so in other words, it was one of those bugs which, magically, don't cause things to break. I *hate* those bugs.