anything wrong with this? (constructor abuse)

ofProjector::ofProjector() {
*this = ofProjector(1024, 768);
}

then it uses the other constructor ofProjector::ofProjector(int width, int height);

for some reason or other i wouldn’t want to use defaults on the arguments

i’m just curious if this is abusive in any way

generally i’d like a way for constructors to call other constructors

Hi,

don’t know if your hack will work, but what is wrong using a private method, which gets called by all of your constructors?

  
  
  
class Test {  
public:   
    Test(int i, int j) { construct(i,j); }  
    Test() { construct(1,2); }  
    Test(const Test2& t2) { construct(t2.getI(), t2.getJ()); }  
private:  
     void construct(int i, int j) { 
 }  
};  
  

cheers,
Stephan

Hi,

some addendum:

if you are willing to switch to C++11, you can call other c’tors, see https://secure.wikimedia.org/wikipedia/en/wiki/C++11#Object-construction-improvement

cheers,
Stephan

ah great!
i was wondering why that was missing from c++ in the first place
i’m making an addon so it’s probably best to avoid compiler specific functioanlity

i usually go via a seperate function, but the hack seemed intriguing (and works fine so far in vs2010 / xcode-llvm)