Showing posts with label tip. Show all posts
Showing posts with label tip. Show all posts

Monday, 7 October 2013

Just to remember: various C++ tips

1. The assignment operator of a derived class must explicitly perform the assignment of it's base class
Derived& Derived::operator =(const Derived& aRhs){
  if( this != &aRhs ){
    Base::operator=(aRhs);
  }
  return *this;
}
2. Virtual destructor is vital for every polymorphic class because it's called when applying operator delete to the pointer of a base type pointing to the object of the derived type.
3. Never pass auto_ptr as reference.
4. Whenever a const auto_ptr is passed or returned as an argument, any attempt to assign a new object results in a compile-time error. With respect to constness, a const auto_prt behaves like a constant pointer (T* const p) not like a pointer that refers to constant (const T* p).
5. auto_ptr as memeber: implement the copy constructor and operator=. By default they transfer ownership.
6. Use const auto_ptr if member is to refer to the same object through all the lifetime.
7. To properly wrap class into Loki::SingletonHolder make the following members private:
  • default constructor
  • copy constructor
  • operator=
  • destructor
  • operator&
8. If any constructor for a class is declared then the compiler won't generate the default one.

Thursday, 4 July 2013

On database link naming

Name dblinks as a site it refers.
For example name it 'subdomain.somesite.com' and then create synonyms to objects on the site:
create synonym some_table for some_table@subdomain.somesite.com
Doing so you help other developers to decipher the site particular database link refers to without consulting all_db_links system view.