Jump to content
  • Advertisement
Sign in to follow this  
Hermes

Is this OK?

This topic is 5403 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

node->succ=new CHead(); ((CHead*)(node->succ))->BuildTree(level++,(turn+1)%2); 1.CHead is derived from CNode 2.node->succ is a pointer to CNode 3.BuildTree is a member function of CHead * Is this Upcast making any slicing?(i think not) * Is there any other way? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Jingo
Though the code is legally valid, its far from ok.


I think, it's beautiful construct!

Well - it could be written on few more lines [smile]

Btw - turn + 1? Why not ++turn, like you used a var before? [smile]

Oxyd

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Hermes
node->succ=new CHead();
((CHead*)(node->succ))->BuildTree(level++,(turn+1)%2);


Oxyd...

++trun and (turn+1) have 2 totally seperate meanings...
==turn modified turn and
(turn+1) mirely uses the value in the var turn.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Quote:
Original post by Hermes
node->succ=new CHead();
((CHead*)(node->succ))->BuildTree(level++,(turn+1)%2);


Oxyd...

++trun and (turn+1) have 2 totally seperate meanings...
==turn modified turn and
(turn+1) mirely uses the value in the var turn.


Lol maybe next time I'll remember to actually log in =)

and it should be...

++trun and (turn+1) have 2 totally seperate meanings...
++turn modified turn
(turn+1) mirely uses the value in the var turn.

Share this post


Link to post
Share on other sites
Well in fact level++ should have also been level+1 i have reasons of my own,it's in fact part of a tree ,and i have many branches on the same level so if i alter the level value at this level it's not ok anymore.

I appreciate your help.
Happy coding guys!

Share this post


Link to post
Share on other sites
I agree that the code is okay, but from a stylistic standpoint it could be made more explicit by breaking out into a couple more lines.

Side effects suck:
((CHead*)(node->succ))->BuildTree(level++,(turn+1)%2);

More clear:
((CHead*)(node->succ))->BuildTree(level,(turn+1)%2);
++level;

Better yet:
foo = (turn + 1) % 2;
((CHead*)(node->succ))->BuildTree(level, foo);
++level;

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!