开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜