C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

calling a constructor within a constructor

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Brett Irving
Guest





PostPosted: Sun Jun 29, 2003 9:37 am    Post subject: calling a constructor within a constructor Reply with 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 help.
Back to top
Rolf Magnus
Guest





PostPosted: Sun Jun 29, 2003 10:13 am    Post subject: Re: calling a constructor within a constructor Reply with quote



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





PostPosted: Sun Jun 29, 2003 10:22 am    Post subject: Re: calling a constructor within a constructor Reply with quote



"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.

Quote:
public:

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





PostPosted: Sun Jun 29, 2003 10:43 am    Post subject: Re: calling a constructor within a constructor Reply with quote


"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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.