Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- //wrap array in struct
- struct INT100
- {
- int val[100] = {0};
- };
- int main(int argc, char* argv[])
- {
- INT100 x;
- // populate it
- for ( auto& i : x.val)
- {
- static int last = 0;
- i = ++last;
- }
- for ( auto i : x.val) std::cout << i << "\t";
- std::cout << std::endl;
- // copy constructor
- INT100 y(x); // copies data
- for ( auto i : y.val) std::cout << i << "\t";
- std::cout << std::endl;
- std::cout << "sizeof(INT100):\t" << sizeof(INT100) << " bytes" << "\n";
- std::cout << "sizeof(x):\t" << sizeof(x) << "\n";
- // copy initialization
- auto z = new INT100{x};
- for ( auto i : z->val) std::cout << i << "\t";
- std::cout << std::endl;
- delete z;
- return 0;
- }
Add Comment
Please, Sign In to add comment