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/ 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/
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/
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/
"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
"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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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;
|
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...
|
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. ...
|
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
|
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. ...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
| |