Mail Archives: djgpp/1998/01/29/20:19:55
,,,
(0 0)
+-------------oOO----(_)-------------------+
| Andrew Deren |
| aderen AT eecs DOT uic DOT edu |
| www.eecs.uic.edu/~aderen/ader/main.html |
+-------------------------oOO--------------+
|| ||
ooO Ooo
On Wed, 28 Jan 1998, Chia wrote:
> I've got two classes... Both of them have lots of constructive arguments,
> and I want to have one of them be contained from the other one. Here's what
> I mean:
>
> class a {
> public:
> a(int b) {
> x = b;
> }
> protected:
> int x;
> }
>
> class b {
> public:
> b(int x) {
> // normally, I would just do this:
> // a class_a_instance(x);
> // but that doesn't seem to work.
> // any ideas on how to call class a's constructor
> // if it's part of another class?
> // thanks! chia AT top DOT net
> }
> protected:
> a class_a_instance;
> }
>
You can define class_a_instance a pointer to class a:
a *class_a_instance;
and then in the constructor just say:
class_a_instance = new a(some_int);
>
- Raw text -