 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Brett Irving Guest
|
Posted: Sun Jun 29, 2003 9:37 am Post subject: calling a constructor within a constructor |
|
|
Hi once again, another question,
I want to make a class object MyArray a global but have no idea about
how to go about initialising it within the constructor as it wont let
me do something like,
private:
int size;
MyArray MyArr(size);
I think I need to call the class constructor something to the effect
of
yourArray(int s, int num): MyArr(s)
{
............
}
My code is similar to this
class MyArray
{
............
MyArray(int size);
}
class yourArray
{
private:
MyArray(int);
public:
..
..
..
..
..
}
please help.
|
|
| Back to top |
|
 |
Rolf Magnus Guest
|
Posted: Sun Jun 29, 2003 10:13 am Post subject: Re: calling a constructor within a constructor |
|
|
Brett Irving wrote:
| Quote: | Hi once again, another question,
I want to make a class object MyArray a global but have no idea about
how to go about initialising it within the constructor as it wont let
me do something like,
private:
int size;
MyArray MyArr(size);
I think I need to call the class constructor something to the effect
of
yourArray(int s, int num): MyArr(s)
{
...........
}
My code is similar to this
class MyArray
{
............
MyArray(int size);
}
class yourArray
{
private:
MyArray(int);
public:
.
.
.
.
.
}
|
Please provide a minimal, but _complete_ example program of what you are
trying. The above code fragments don't make sense.
|
|
| Back to top |
|
 |
David White Guest
|
Posted: Sun Jun 29, 2003 10:22 am Post subject: Re: calling a constructor within a constructor |
|
|
"Brett Irving" <balgorg (AT) hotmail (DOT) com> wrote
| Quote: | Hi once again, another question,
I want to make a class object MyArray a global but have no idea about
how to go about initialising it within the constructor as it wont let
me do something like,
private:
int size;
MyArray MyArr(size);
I think I need to call the class constructor something to the effect
of
yourArray(int s, int num): MyArr(s)
{
...........
}
My code is similar to this
class MyArray
{
............
MyArray(int size);
}
class yourArray
{
private:
MyArray(int);
|
Make it:
MyArray myArray;
where 'myArray' is just a member variable name of your choice.
Your constructor will look something like:
yourArray::yourArray(int s, int num) : myArray(s) {}
However, this will not make it "global" as you requested. A MyArray object
will be in every yourArray object.
David
|
|
| Back to top |
|
 |
John Harrison Guest
|
Posted: Sun Jun 29, 2003 10:43 am Post subject: Re: calling a constructor within a constructor |
|
|
"Brett Irving" <balgorg (AT) hotmail (DOT) com> wrote
| Quote: | Hi once again, another question,
I want to make a class object MyArray a global but have no idea about
how to go about initialising it within the constructor as it wont let
me do something like,
|
You should stop using the word global to mean what every one else calls a
member variable.
And you should post more complete code.
john
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|