constructor C++ example

The constructor for this class could be defined, as usual, as:

 
Rectangle::Rectangle (int x, int y) { width=x; height=y; }
 


But it could also be defined using member initialization as:

 
Rectangle::Rectangle (int x, int y) : width(x) { height=y; }
 


Or even:

 
Rectangle::Rectangle (int x, int y) : width(x), height(y) { }
 
posted @ 2015-04-08 06:21  vigorpush  阅读(87)  评论(0编辑  收藏  举报