I read some articles when it says that you should not use the 'this' keyword in the constructor, while others should be the exact opposite ....
Now my main question is: is it safe and good to use the 'this' constructor in the constructor?
This question leads to others:
- How is an object created?
- When are class members created? Before calling the constructor?
Here are some examples of working with VS2012 on windows 7:
class FirstClass { int m_A; public: FirstClass( int a ) : m_A( a ) { std::cout << this->m_A << std::endl;
and:
class ThirdClass; // forward decl class SecondClass { public: SecondClass( ThirdClass* iTC ) { // ... } }; class ThirdClass { SecondClass* m_SC; public: ThirdClass(): m_SC( new SecondClass( this ) ) // ^^^^ { //... } };
These examples work, but is it likely to have undefined behavior?
source share