2

How do I write a ctor definition which has both throw and a member initialisation list? Is this correct?

ClassName::ClassName(int parameter): datamember_(parameter) throw(ExceptionType)
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
The Void
  • 857
  • 2
  • 7
  • 6

1 Answers1

5

The throw thing is part of the function declarator, therefore it should appear before the initialization list (the :).

ClassName::ClassName(int parameter) throw(ExceptionType) : datamember_(parameter) {

BTW, exception specification is deprecated in C++0x, and except throw() it is generally useless. See Should I use an exception specifier in C++?.

Community
  • 1
  • 1
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
  • If throw is part of the function signature, does it mean that the following (declarations) are valid overloads (given that the above function exists): ClassName(int parameter) const throw(ExceptionType); ClassName(int parameter) throw(ExceptionType2); ClassName(int parameter) const throw(ExceptionType2); – The Void Jul 31 '10 at 08:47
  • @The It's not part of the signature as regards overloading, so no, you can't. –  Jul 31 '10 at 09:03