Jump to content
  • Advertisement
Sign in to follow this  

c++ Programming

This topic is 2680 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have this cod "hgrd_demo":

typedef list<HGrdTri*> 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 :D

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!