Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //daughterstruct.hpp
- struct Daughter
- {
- int** p_pa;
- int** p_pb;
- Daughter()
- {
- }
- Daughter(int** a, int** b)
- {
- p_pa = a;
- p_pb = b;
- }
- };
- //motherstruct.hpp
- #include"daughterstruct.hpp"
- struct Mother
- {
- int* p_a;
- int* p_b;
- int num1;
- int num2;
- int num3;
- int num4;
- Daughter daughter;
- Mother()
- {
- daughter = Daughter(&p_a, &p_b);
- p_a = &num1;
- p_b = &num2;
- num1 = 22;
- num2 = 0;
- num3 = 65;
- num4= 100;
- }
- ~Mother()
- {
- p_a = NULL;
- p_b = NULL;
- }
- void swap()
- {
- p_a = &num3;
- p_b = &num4;
- }
- };
- //main.cpp
- #include<iostream>
- #include"motherstruct.hpp"
- void main()
- {
- Mother mom;
- std::cout << mom.num1 << std::endl;
- std::cout << *mom.p_a << std::endl;
- std::cout << **mom.daught.p_pa << std::endl;
- // mom.p_a is pointing to mom.num3, and mom.daught.p_pa is pointing to mom.p_a
- mom.swap();
- std::cout<<mom.num3 << std::endl;
- std::cout<<*mom.p_a << std::endl;
- std::cout<<**mom.daught.p_pa << std::endl;
- /*
- std::cout << mom.num1 << std::endl;
- std::cout << *mom.p_a << std::endl;
- std::cout << *mom.daught.p_pa << std::endl;
- mom.swap();
- std::cout << mom.num1 << std::endl;
- std::cout << *mom.p_a << std::endl;
- std::cout << *mom.daught.p_pa << std::endl;
- */
- }
Add Comment
Please, Sign In to add comment