Probably trivial C++ error, but not for me.

Member
Posts: 321
Joined: 2004.10
Post: #1
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.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #2
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.
Quote this message in a reply
Member
Posts: 321
Joined: 2004.10
Post: #3
Yes! Thank you very much. (Although Codewarrior was treating it
like a valid invocation, because it was creating output).
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #4
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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  hopefully not a trivial question... krazygluon 4 2,702 May 21, 2006 03:51 PM
Last Post: codemattic