tags:

views:

74

answers:

1

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)
+5  A: 

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++?.

KennyTM
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
@The: No. _____
KennyTM
@The It's not part of the signature as regards overloading, so no, you can't.
anon