Hi,
I've been working with Java for a while and had minimal c++ experience before, although a lot of c experience. So most of the problems I'm running into have to do with the way c++ handles objects since it is a bit different than Java. On to the question...
I know how to overload constructors and I can use them like so:
As yo can see there's a lot of repetition there. Is there a way to call other constructors from within a constructor? Like...Code:Rectangle::Rectangle(void) { this->theta = 0; this->validateRotation(); } Rectangle::Rectangle(int width, int height) { this->width = width; this->height= height; this->theta = 0; this->validateRotation(); } Rectangle::Rectangle(int width, int height, Point2D center) { this->width = width; this->height= height; this->center = center; this->theta = 0; this->validateRotation(); }
I tried that but it doesn't compile, I figured this may work since I have a subclass of Rectangle where I can do that (and it compiles fine). Is it possible to do this?Code:Rectangle::Rectangle(void) { this->theta = 0; this->validateRotation(); } Rectangle::Rectangle(int width, int height) : Rectangle() { this->width = width; this->height= height; } Rectangle::Rectangle(int width, int height, Point2D center) : Rectangle(width,height) { this->center = center; }
Thanks



LinkBack URL
About LinkBacks


