Jump to content
Sign in to follow this  
  • entries
    12
  • comments
    26
  • views
    17516

Don't do this

Sign in to follow this  
MrEvil

229 views

Imagine you have a C++ class 'program', which takes a reference to a stack in its constructor.


template
struct program{
typedef T value_type;
stack& stk;

program(stack& stk): stk(stk)
{}

void operator()(){}
};



That's all very well, until you decide to have the stack as a member variable, and it changes to this.

template
struct program{
typedef T value_type;
stack stk;

program(): stk(stk)
{}

void operator()(){}
};


Obviously I should have got rid of the stk(stk) initialiser, but this is a really simpilified example; in my code the constructor code was in a different file and there were about 15 initialisers.

Your stk is now being initialised by itself. On my system, which was g++ 3.3.3 on cygwin, it went into an infinite loop where it eventually ran out of memory.

My question is, shouldn't it have at least warned me about that?
Sign in to follow this  


4 Comments


Recommended Comments

Hey there MrEvil! Welcome to journal land! I don't think I can answer your question, but compilers don't usually warn of run-time errors, those are usually out of it's scope.

And a hearty rating++ to you :)

Share this comment


Link to comment
Superhappyratingsrape. Welcome to Journal Land. One for the programmer team, whoo hoo!

Do not use evil_fraction_math(). It will be your downfall.

-IV

Share this comment


Link to comment
Thanks [smile]

I guess this means I have to update it once in a while.. [grin]

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!