-
May 17th, 2001, 02:45 AM
#1
nested classes
Hi,
I have this problem:
class A
{
class B
{
A a;
};
};
The problem is that I can't use class A within class B because class A has not yet been declared entirely.
Is there any way to declare a nest class outside the base class so the nested class can use the base class?
Thanx.
-
May 17th, 2001, 03:03 AM
#2
Re: nested classes
Hi,
I dont think that u can declare like that. Why do you want to declare an object of class A in class B? You can any way access all the members of A. Can you tell me a practical situation like that?
John
Let me know if got helped. If you got helped pls rate!!!
Jus hav a look at http://www.bobbyzone.homestead.com
-
May 17th, 2001, 03:14 AM
#3
Re: nested classes
Hi,
Yes you can declare this, its used mostly for hiding helper classes that can only been used by your base class and you don't want to accidentally use them.
-
May 17th, 2001, 03:55 AM
#4
Re: nested classes
Hi,
Have you tried template, instead of writing class A in class B? And then when you call the class a, you can fill in the exact class insteadof the template.
class A
{
class B
{
template a;
};
};
Best regards,
Hao
-
May 17th, 2001, 04:16 AM
#5
Re: nested classes
Hi,
I'm not aware of this syntax of template keyword, can you spare a little time for explain it to me? I'll be grateful.
Thanks for replying.
-
May 17th, 2001, 08:20 AM
#6
Re: nested classes
Hi,
Sorry for my delay.
According to your question, I think maybe we can find another way. For example,
class A;
class B{
A a;
};
class A{
B b;
};
Do you think it easier and can also satisfy you?
Hao
-
May 17th, 2001, 08:40 AM
#7
Re: nested classes
No, sorry.
I think that the solution will be something like this (I can't test it right now because I don't have a compiler in this computer)
class A
{
class B;
};
class A::B
{
A a;
};
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|