开发者

C++ Syntax question regarding constructor's member initialisation list and throw

开发者 https://www.devze.com 2023-01-09 11:52 出处:网络
How do I write a ctor definition which has both throw and a member initialisation list? Is thi开发者_运维知识库s correct?

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

精彩评论

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

关注公众号