Hi
Someone was saying that an object can exist within an object. The discussion was about classes. I know that a class can exist within a class but don't get how an object can exist within some other object. Does it make any sense to you? Please let me know. Thank you.
Regards
Jackson
2 replies to this topic
#1
Posted 29 October 2011 - 02:52 AM
I'm an outright beginner, learning C++. Using Win XP Pro and Code::Blocks. Be nice to me, please.:)
|
|
|
#2
Posted 29 October 2011 - 04:26 AM
An object exists within another object only when a class contains other objects or classes
class X
{
public:
int x;
}
int main()
{
X h; // now h contains an instance of x
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.
#3
Posted 30 October 2011 - 05:18 AM
Yes.
class X
{
public:
int a;
};
class Y
{
public:
X x;
};
int main()
{
Y g; //here object g contains x which is object of X
g.x.a=10;
}
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









