JohnQ said:
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).
The one above is the only constructor (once you declare/define one, the
compiler does not). It seconds as the default constructor (can be called
with no args).
Fine. Now how about:
Rect rect8(); // ambiguous
Declaration of function 'rect8' which takes no parameters, and returns an
'Rect'.
You meant:
Rect rect8; // default construct, like below (rect2)
Same with built-in types:
int number();
number = 43;
// error: assignment of function `int number()'
// error: cannot convert `int' to `int ()()' in assignment
int number2( 34 ); // or: int number2;
number2 = 43; // ok
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).
Remember it's an POD, the compiler supplied copy-ctor is fine.
And destructor, assignment operator. As soon as you define one of the three,
you should supply all three.
Same question as above (and excuse me if I am at times unpedantic).
Same answer as above.
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))!
John
"summed up", the answer is "no".
You seem reluctant to believe that POD struct/class have the guts supplied.
Try this:
#include <iostream>
struct Bint{ int x; }; // don't come much 'plainer'
int main(){
Bint bint1; // default construct
bint1.x = 3;
Bint bint2;
bint2 = bint1; // assignment
Bint bint3( bint1 ); // copy-ctor
std::cout<<"bint1.x="<<bint1.x<<'\n';
std::cout<<"bint2.x="<<bint2.x<<'\n';
std::cout<<"bint3.x="<<bint3.x<<'\n';
return 0;
}
/* -out-
bint1.x=3
bint2.x=3
bint3.x=3
*/