Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) delegation

 

delegation is a technique that can be used, depending on the standard used:

 

 

 

 

 

C++98 delegation in the C++98 standard

 

Delegation is not supported in C++98.

 

 

 

 

 

C++0x delegation in the C++0x standard

 

 

Delegation is the technique of constructors calling each other:

 

struct MyClass
{
  MyClass() : MyClass(42) {}
  MyClass(const int x) : m_x(x) {}
  int m_x;
};

int main()
{
  MyClass a;
  MyClass b(1);
}

 

Technical note: the code shown did not compile using the G++ 4.4.5 compiler, which is supplied with the Qt Creator 2.0.0 IDE, but is expected to compile in a future G++ version [1].

 

 

 

 

 

References

 

  1. GCC page about C++0x support

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict