By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,407 Members | 920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,407 IT Pros & Developers. It's quick & easy.

Multiple classes

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Surya Kiran" <sk*@fluent.co.in> wrote...
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
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.