Mail Archives: djgpp/1998/01/29/06:37:20
>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
This is not djgpp specific, it was better posting to comp.lang.c++...
anyway...
>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;
>}
if you declare a member of class "a" you must provide a default constructor
for
that class (i.e. a constructor without arguments).
you can try one of these:
1) class b : public a {
b(int x) : a(x) { ...
2) a *class_a_instance;
b(int x) { class_a_instance = new a(x); ...
of course c++ allows other MAXINT more solutions, but two is a beginning
:-)
ciao
Giacomo
- Raw text -