473,382 Members | 1,786 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,382 software developers and data experts.

asking for suggestions.Thanks.

In the following source code,
class CA
{
CB b1;

void funca()
{
b1.funcb();
};
.......
};

void main
{
CB bArray[6];
....
}

I am hoping that, in class CA, b1 is exactly same as bArray[1] in the main
program. That means, for funca in CA, b1.funcb() is same as
bArray[1].funcb().

The only approach i can think about is defining bArray as a global variable.
Any other techniques? Thank you very much.

--
***********MERRY CHRISMAS***************
Thanks and Best Regards

Yan ZHANG
http://www.nict.com.sg/zhang/
Jul 22 '05 #1
5 1272
bArray in your code is a definition, while CA is a declaration of a class.
So, what's your meaning?
I guess you want to get a instance of CA, which has the member b1 identical
with bArray[1]. Simply, you can define a constructor for CA to initiate its
member b1. Whenever you want a object of CA, you just pass bArray[1] to the
constructor.
bArray does not have to be a global variable.
"Yan ZHANG" <bu******@sina.com> wrote in message news:33*************@individual.net...
In the following source code,
class CA
{
CB b1;

void funca()
{
b1.funcb();
};
......
};

void main
{
CB bArray[6];
...
}

I am hoping that, in class CA, b1 is exactly same as bArray[1] in the main
program. That means, for funca in CA, b1.funcb() is same as
bArray[1].funcb().

The only approach i can think about is defining bArray as a global variable.
Any other techniques? Thank you very much.

--
***********MERRY CHRISMAS***************
Thanks and Best Regards

Yan ZHANG
http://www.nict.com.sg/zhang/

Jul 22 '05 #2
Thank you very much for your comments. do you mind give some sample source
code for this? Thanks a lot!
"Mole Wang" <mo****@yahoo.com.cn> wrote in message
news:cq**********@mail.cn99.com...
bArray in your code is a definition, while CA is a declaration of a class.
So, what's your meaning?
I guess you want to get a instance of CA, which has the member b1 identical with bArray[1]. Simply, you can define a constructor for CA to initiate its member b1. Whenever you want a object of CA, you just pass bArray[1] to the constructor.
bArray does not have to be a global variable.
"Yan ZHANG" <bu******@sina.com> wrote in message

news:33*************@individual.net...
In the following source code,
class CA
{
CB b1;

void funca()
{
b1.funcb();
};
......
};

void main
{
CB bArray[6];
...
}

I am hoping that, in class CA, b1 is exactly same as bArray[1] in the main program. That means, for funca in CA, b1.funcb() is same as
bArray[1].funcb().

The only approach i can think about is defining bArray as a global variable. Any other techniques? Thank you very much.

--
***********MERRY CHRISMAS***************
Thanks and Best Regards

Yan ZHANG
http://www.nict.com.sg/zhang/


Jul 22 '05 #3
class CA {
CB b1;
public:
CA(const CB &b) : b1(b) {}
void funca() {
b1.funcb();
}
};
void main()
{
CB bArray[6];
..................
CA ca(bArray[1]);
}
CB must have a well-defined copy constructor.
I hope this is helpful.

"Yan ZHANG" <bu******@sina.com> wrote in message news:33*************@individual.net...
Thank you very much for your comments. do you mind give some sample source
code for this? Thanks a lot!
"Mole Wang" <mo****@yahoo.com.cn> wrote in message
news:cq**********@mail.cn99.com...
bArray in your code is a definition, while CA is a declaration of a class.
So, what's your meaning?
I guess you want to get a instance of CA, which has the member b1

identical
with bArray[1]. Simply, you can define a constructor for CA to initiate

its
member b1. Whenever you want a object of CA, you just pass bArray[1] to

the
constructor.
bArray does not have to be a global variable.
"Yan ZHANG" <bu******@sina.com> wrote in message

news:33*************@individual.net...
In the following source code,
class CA
{
CB b1;

void funca()
{
b1.funcb();
};
......
};

void main
{
CB bArray[6];
...
}

I am hoping that, in class CA, b1 is exactly same as bArray[1] in the main program. That means, for funca in CA, b1.funcb() is same as
bArray[1].funcb().

The only approach i can think about is defining bArray as a global variable. Any other techniques? Thank you very much.

--
***********MERRY CHRISMAS***************
Thanks and Best Regards

Yan ZHANG
http://www.nict.com.sg/zhang/



Jul 22 '05 #4

"Yan ZHANG" <bu******@sina.com> a écrit dans le message de news:
33*************@individual.net...
In the following source code,
class CA
{
CB b1;

void funca()
{
b1.funcb();
};
......
};

void main
main() returns an int.

int main()
{
CB bArray[6];
...
}

I am hoping that, in class CA, b1 is exactly same as bArray[1] in the main
program. That means, for funca in CA, b1.funcb() is same as
bArray[1].funcb().
Be careful with the words you use. Differentiate between object and class.
The only approach i can think about is defining bArray as a global
variable.
Any other techniques? Thank you very much.


You need CA to have a reference to an object.

class CA
{
private:
CB &cb_;

public:
CA(CB &cb)
: cb_(cb)
{
}

void f()
{
cb_.g();
}
};

int main()
{
CB cbs[6];

CA ca(cbs[1]);
ca.f(); // calls cbs[1].g()
}
Jonathan
Jul 22 '05 #5
"Mole Wang" <mo****@yahoo.com.cn> a écrit dans le message de news:
cq**********@mail.cn99.com...
"Yan ZHANG" <bu******@sina.com> wrote in message
news:33*************@individual.net...
Thank you very much for your comments. do you mind give some sample
source
code for this? Thanks a lot!
"Mole Wang" <mo****@yahoo.com.cn> wrote in message
news:cq**********@mail.cn99.com...
> bArray in your code is a definition, while CA is a declaration of a
> class.
> So, what's your meaning?
> I guess you want to get a instance of CA, which has the member b1 identical
> with bArray[1]. Simply, you can define a constructor for CA to initiate

its
> member b1. Whenever you want a object of CA, you just pass bArray[1] to

the
> constructor.
> bArray does not have to be a global variable.
>
>
> "Yan ZHANG" <bu******@sina.com> wrote in message

news:33*************@individual.net...
> > In the following source code,
> > class CA
> > {
> > CB b1;
> >
> > void funca()
> > {
> > b1.funcb();
> > };
> > ......
> > };
> >
> > void main
> > {
> > CB bArray[6];
> > ...
> > }
> >
> > I am hoping that, in class CA, b1 is exactly same as bArray[1] in the

main
> > program. That means, for funca in CA, b1.funcb() is same as
> > bArray[1].funcb().
> >
> > The only approach i can think about is defining bArray as a global

variable.
> > Any other techniques? Thank you very much.


Don't top-post. Rearranged.
class CA {
CB b1;
That should be

CB &b1;

if you don't want to copy the object.
public:
CA(const CB &b) : b1(b) {}
void funca() {
b1.funcb();
}
};
void main()
main() ALWAYS returns an int.

int main() {
CB bArray[6];
.................
CA ca(bArray[1]);
}
CB must have a well-defined copy constructor.
I hope this is helpful.

Jonathan
Jul 22 '05 #6

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

Similar topics

6
by: Christine | last post by:
I am looking for some good C/C++ tutorials either online or in book form. I am using Dev C/C++ 4 (from www.bloodshed.net) and I am using WindowsXP operating system. I don't have the money for...
0
by: Stefan Engstr?m | last post by:
My mysql is responding strangely to a select when I try to ask for particular columns instead of everything. Here is an example which is querying a database of a few thousand elements in each...
3
by: Robert Hogan | last post by:
Hello all, I have a client with an application that they have purchased, it stores its data on SQL server 2000 and so I am able to do reports and some small VB apps that use the data. I can't...
258
by: Terry Andersen | last post by:
If I have: struct one_{ unsigned int one_1; unsigned short one_2; unsigned short one_3; }; struct two_{ unsigned int two_1;
1
by: Brian Basquille | last post by:
Hello all. Have been working on the Air Hockey game on and off for a couple of weeks now.. but have had plenty of other assignments to keep me busy along with it. But i would like some...
62
by: A.M. Kuchling | last post by:
Here are some thoughts on reorganizing Python's documentation, with one big suggestion. The tutorial seems to be in pretty good shape because Raymond Hettinger has been keeping it up to date. ...
17
by: I_got_questions? | last post by:
I just started c programming. I want to migrate to c++. I know a little bit about class/inheritance. I am asking for good books to read. Elementary will be good. Thanks for any comments
1
by: AparnaKulkarni | last post by:
Want to call a crystal report of version 8.5 through VB.NET. In this the data is passed to report through XML file. On running this, the report asks for Database name, Server name, Userid, Pwd. ...
7
Nert
by: Nert | last post by:
hi, I have made a simple website that allows users to upload videos. The videos are automatically converted into flv using the ffmpeg. I'm executing the ffmpeg using the PHP function exec(). My...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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.