Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

file.h:

extern objekt squares[120];

file.cpp:

objekt squares[120]= {objekt(objekt_size ,objekt_size ,-111,0)};

How can I init all objects at one time, all with the same parameters?

share|improve this question
1  
Is typing "please" really all that difficult? Edited. –  Billy ONeal Feb 12 '11 at 22:54

2 Answers 2

Don't use a raw array (because all the elements will be initialised via the default constructor). Use e.g. a std::vector:

std::vector<objekt> squares(120, objekt(objekt_size ,objekt_size ,-111,0));
share|improve this answer
    
argh, you beat me to it –  Cheers and hth. - Alf Feb 12 '11 at 21:08
    
Is this the only possibility? And what would be the pointer-solution? –  Vincent Feb 12 '11 at 21:38
    
@Vincent: What pointer solution? –  Oli Charlesworth Feb 12 '11 at 21:49

You can also use the preprocessor to repeat the same code 120 times.

#include <boost/preprocessor/repetition/enum.hpp>

#define TO_BE_ENUMERATED(z, n, text) text

objekt squares[120] = {
    BOOST_PP_ENUM(120, TO_BE_ENUMERATED, objekt(objekt_size ,objekt_size ,-111,0))
};
#undef TO_BE_ENUMERATED
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.