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::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 daught;
- MOTHER()
- {
- daught=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>
- using namespace std;
- #include"motherstruct.hpp"
- void main()
- {
- MOTHER mom;
- //what I'm doing
- cout<<mom.num1<<endl;
- cout<<*mom.p_a<<endl;
- cout<<**mom.daught.p_pa<<endl;
- //swap
- mom.swap(); //mom.p_a is pointing to mom.num3, and mom.daught.p_pa is pointing to mom.p_a
- //this would be easier if I just had a reference to mom.p_a in the daughter class!
- cout<<mom.num3<<endl;
- cout<<*mom.p_a<<endl;
- cout<<**mom.daught.p_pa<<endl;
- ///
- //what I'm tryng to do
- /*
- cout<<mom.num1<<endl;
- cout<<*mom.p_a<<endl;
- cout<<*mom.daught.p_pa<<endl; //mom.daught.p_pa is a reference to mom.daught.p_a
- //swap
- mom.swap();
- cout<<mom.num1<<endl;
- cout<<*mom.p_a<<endl;
- cout<<*mom.daught.p_pa<<endl;
- */
- }
Add Comment
Please, Sign In to add comment