access an object

Hi,

Assuming, i have the following code..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

//obj1

class obj1{ 
obj1();
void foo();
.......
};
// file1.cpp

int main{
...
obj1 Ob;
.....
} 

//file2

class obj2{ 
obj2();
.......
};

//file3

class obj3{ 
obj3();
.........
};


my question is, how can i access the instance 'Ob' in the main.cpp from the constructor of ther classes without instancing them in the main file. Something like that:
1
2
3
4
5
6
7
8
class obj3{ 
obj3();
.........
};
obj3::obj3(){

Ob.foo();  // how can i implement it
}


please help

thanks
You need to pass the object as a parameter to the constructor.
thank...

but could you please a bit more clerify what you mean?


thanks a lot again..
1
2
3
obj3::obj3(obj1 &obj){
//...
}
Topic archived. No new replies allowed.