Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
Why can't PODs have constructors?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="BobR, post: 2989421"] 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). 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 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 answer as above. "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 */ [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
Why can't PODs have constructors?
Top