473,378 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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.
Jul 19 '05 #1
3 2850
Brett Irving wrote:
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.

Jul 19 '05 #2
"Brett Irving" <ba*****@hotmail.com> wrote in message
news:4f*************************@posting.google.co m...
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.
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

Jul 19 '05 #3

"Brett Irving" <ba*****@hotmail.com> wrote in message
news:4f*************************@posting.google.co m...
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
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Murat Tasan | last post by:
i have a quick question... is there a way to obtain the reference to the object which called the currently executing method? here is the scenario, i have a class and a field which i would like to...
3
by: MC D | last post by:
Is it possible to call an objects constructor method from within the class somehow? The class I have populates itself with data from a sqlServer database when it is constructed, and I want to...
31
by: Peter E. Granger | last post by:
I'm fairly new to C++ and VC++, but for the most part it seems to do most of the same things that can be done in Java, with just some syntactic and structural adjustments. However, one thing I...
5
by: Bennett Haselton | last post by:
I've noticed that if you enter the following code in the codebehind page for an .aspx page, it won't compile because the call to Trace.Write() is not valid except in methods of a class derived from...
1
by: JezB | last post by:
In my Page_Load event of all my web app Pages and UserControls I instantiate the same library class "TextResources" (to take care of reading presentation text strings from localizable resource...
12
by: st_ev_fe | last post by:
I've noticed that when constructing a subclass, the base class get's it's contructors called. Is there some way to avoid this? The base class has one variable, which gets initialised to 0. ...
4
by: Michael | last post by:
Hello, I want to use an object (LowCut) within another object (SampleRateConverter) like it is written as follows: class SampleRateConverter { public: SampleRateConverter( int...
4
by: Rob Blackmore | last post by:
Hi, Can anyone advise how to call a private constructor using reflection? I currently get the above error which is rectified by changing the New() to Public from Friend but I ideally wish to...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.