C++ Syntax question regarding constructor's member initialisation list and throw
How do I write a ctor definition which has both throw and a member initialisation list? Is thi开发者_运维知识库s correct?
ClassName::ClassName(int parameter): datamember_(parameter) throw(ExceptionType)
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++?.
精彩评论