Call a non member funcion on an instance before is constructed.

Posted by Tom on Stack Overflow See other posts from Stack Overflow or by Tom
Published on 2010-04-15T04:17:04Z Indexed on 2010/04/15 4:23 UTC
Read the original article Hit count: 130

Hi everyone.

I'm writing a class, and this doubt came up. Is this undef. behaviour? On the other hand, I'm not sure its recommended, or if its a good practice. Is it one if I ensure no exceptions to be thrown in the init function?

//c.h
class C{

    float vx,vy;
    friend void init(C& c);
public:
    C();
    ~C();
};


//c.cpp
C::C()
{
   init(*this);
}

void init(C& c) //throws() to ensure no exceptions ?
{
  c.vx = 0;
  c.vy = 0;
}

Thanks in advance

© Stack Overflow or respective owner

Related posts about c++

Related posts about init