Multiple classes

S

Surya Kiran

Hi
I'm a newbie to c++
here is my problem.
I've two classes
class A and class B. and i've a main function

main function creates an instance of class A by defining like this.

int main()
{
...
A *newa = new A () ;
}

now in class B can i access the same newa instance of class A.
I want every instance of class B to access the newa instance of class A.
how can i do that..
Thanks in advance.

Surya
 
V

Victor Bazarov

Surya Kiran said:
I'm a newbie to c++
here is my problem.
I've two classes
class A and class B. and i've a main function

main function creates an instance of class A by defining like this.

int main()
{
...
A *newa = new A () ;
}

now in class B can i access the same newa instance of class A.
I want every instance of class B to access the newa instance of class A.
how can i do that..

Add a static member to class B, make it of type A*, and then
assign it when you know what value it should be. Every instance
of B will be able to see it.

Next time please do your own homework.

Victor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,356
Latest member
Tommyhotly

Latest Threads

Top