Skip to main content
gamedev.net
🔒 Locked

c++ Programming

Started by davood_m Aug 17, 2011 at 10:07 AM 0 replies 1.3k views
Original Post
davood_m
davood_m
Hi,
I have this cod "hgrd_demo":

typedef list CollGCell;
typedef CollGCell::iterator IterGCell;

.
.
.

IterGCell NextCell( HFroSeg *pseg, IterGCell& iclprv=NULL);




The code compiles fine in Debug mode, but when compiling in Release mode I get the following error:

hgrid.h(99) : error C2440: 'default argument' : cannot convert from 'int' to 'const HGrdTri::IterGCell &'
Reason: cannot convert from 'int' to 'const HGrdTri::IterGCell'
No constructor could take the source type, or constructor overload resolution was ambiguous

The line corresponding to the error is "IterGCell NextCell( HFroSeg *pseg, const IterGCell& iclprv=NULL);"

If I remove the =NULL part it sets off a bunch of other errors all concerned with either default arguments or comparisons using NULL.

If I just run in debug mode, it will get to "if ( Cell(0) != NULL)" in HGridTri::NextCell and throw an error. "Debug Assertion Failed... [filepath]\list... Line: 309... Expression: list iterators incompatable"

Ran the included demo in debug mode (without following it with breakpoints like above) and it bailed and wrote a blank trace.txt.

Any ideas?


.
.
.
inline void HGrdTri::DumpTri()
{
char sbuf[256];
sprintf( sbuf, "n0 = (%lg %lg) n1 = (%lg %lg) n2 = (%lg %lg)",
(*Node(0))->X(), (*Node(0))->Y(),
(*Node(1))->X(), (*Node(1))->Y(),
(*Node(2))->X(), (*Node(2))->Y() );

TRACE( sbuf);

void *cp0, *cp1, *cp2;

cp0 = cp1 = cp2 = NULL;
if ( Cell(0) != NULL)
cp0 = *Cell(0);

if ( Cell(1) != NULL)
cp1 = *Cell(1);

if ( Cell(2) != NULL)
cp2 = *Cell(2);

//sprintf( sbuf, "c0 = (%p %p) c1 = (%p %p) c2 = (%p %p)", Cell(0), cp0, Cell(1), cp1, Cell(2), cp2);
sprintf( sbuf, "c0 = (%p) c1 = (%p) c2 = (%p)", cp0, cp1, cp2);

TRACE( sbuf);
}

this code from site : http://www.codeproje...218#xx3995218xx
and attach code File
please answer
rip-off
rip-off
Well, the code is meaningless. Assigning a reference to an iterator to NULL? What do you expect that to mean?

NULL has meaning with pointers, but not elsewhere (the fact that it is usable as an integer constant confuses things). For iterators, you compare with the "end" iterator provided by the container.

As for why it works in Debug and not in Release, I don't know. Many runtimes provide different implementations of iterators in debug, to assert you are using them correctly. As a side effect of these changes, it might be possible to construct a std::list::iterator from an integer or null pointer constant. If you have language extensions enabled it might be trying to construct a temporary iterator from this, bind it to the (non-const) reference... maybe.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.