Re: Why can't PODs have constructors?
"BobR" <removeBadBobR@worldnet.att.net> wrote in message
news:W6sqi.6230$ax1.412@bgtnsc05-news.ops.worldnet.att.net...
JohnQ <johnqREMOVETHISprogrammer@yahoo.com> wrote in message...
"BobR" wrote in message...
struct MyRect : public virtual RECT{
Why the virtual inheritance?
Oops.
I was cleaning out my 'TestBench' program, and removed the wrong code
(had about 5 versions).
Here is the one I meant to post:
struct Rect : RECT{
Rect( long x1 = 0, long y1 = 0, long x2 = 10, long y2 = 10 ){
left = x1; bottom = y1; right = x2; top = y2;}
How will the compiler be able to distinguish between using the default
constructor and the one above where you gave default values to all the
arguments? (This is a minor note that is off-topic for the thread).
};
{ // main() or ?
using std::cout // for NG post
Rect rect( 10, 12, 22, 42 );
Fine. Now how about:
Rect rect8(); // ambiguous
RECT rect1( rect );
Can't do that because RECT has not constructor taking a Rect arg. Are you
suggesting that initializing a struct with a struct (from the RECT& operator
of Rect) works? (My C-ismness, or forgetfulness thereof may be apparent).
RECT rect1a( Rect( 7, 14, 27, 34 ) );
Same question as above (and excuse me if I am at times unpedantic).
Rect rect2;
cout<<" Rect rect.bottom="<< rect.bottom <<'\n'
<<" RECT rect1.bottom="<< rect1.bottom <<'\n'
<<" RECT rect1a.bottom="<< rect1a.bottom <<'\n'
<<" Rect rect2.top="<< rect2.top <<'\n'
<<" sizeof(rect)="<<sizeof(rect)<<'\n'
<<" sizeof(rect1)="<<sizeof(rect1)<<std::endl;
}
/* - output -
Rect rect.bottom=12
RECT rect1.bottom=12
RECT rect1a.bottom=14
Rect rect2.top=10
sizeof(rect)=16
sizeof(rect1)=16
*/
Sorry about that.
What you should be sorry for is making me decipher your examples rather than
just stating the obvious (which I think I "summed up" in a near previous
post in this thread (kind of))! :P ;)
John