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

Class in class problem

Yes, it's Xmas and I'm working...

Got a problem (of course).
*****

class CPlatform
{
private:
CActuator actuator0(0);

public:
...
};

CActuator actuator0(0);

I get errors when I try to construct a class variable with a parameter inside
CPlatform, but no error when I do the same just underneath it (global variable).

What's going on?

thanks
Dirk

The Consensus:-
The political party for the new millenium
http://www.theconsensus.org
Dec 23 '05 #1
9 1259
Hi,

You can't do it that way, you have to do it when constructing the class:

CPlatform::CPlatform():
actuator0(0)
{

}

--
Regards, Ron AF Greve

http://moonlit.xs4all.nl

"Dirk Bruere at Neopax" <di*********@gmail.com> wrote in message
news:41*************@individual.net...
Yes, it's Xmas and I'm working...

Got a problem (of course).
*****

class CPlatform
{
private:
CActuator actuator0(0);

public:
... };

CActuator actuator0(0);

I get errors when I try to construct a class variable with a parameter
inside CPlatform, but no error when I do the same just underneath it
(global variable).

What's going on?

thanks
Dirk

The Consensus:-
The political party for the new millenium
http://www.theconsensus.org

Dec 23 '05 #2
Dirk Bruere at Neopax wrote:
Yes, it's Xmas and I'm working...
It's not Xmas yet.
Got a problem (of course).
*****

class CPlatform
{
private:
CActuator actuator0(0);
This is an attempt to initialise a non-static member where there can be no
initialiser. Read about initialising members properly.
public:
...
};

CActuator actuator0(0);

I get errors when I try to construct a class variable with a parameter
inside CPlatform, but no error when I do the same just underneath it
(global variable).

What's going on?


Nothing. Learn C++. Read about constructors and initialiser lists.

V
Dec 23 '05 #3
Moonlit wrote:
Hi,

You can't do it that way, you have to do it when constructing the class:

CPlatform::CPlatform():
actuator0(0)
{

}


In that case it might be more transparent to use the default constructor:

class CPlatform
{
private:
CActuator actuator0;

public:
CPlatform(){actuator0.SetNumber(0);}
};

Any problems doing it this way?

--
Dirk

The Consensus:-
The political party for the new millenium
http://www.theconsensus.org
Dec 23 '05 #4
Victor Bazarov wrote:
Dirk Bruere at Neopax wrote:
Yes, it's Xmas and I'm working...

It's not Xmas yet.
Got a problem (of course).
*****

class CPlatform
{
private:
CActuator actuator0(0);

This is an attempt to initialise a non-static member where there can be
no initialiser. Read about initialising members properly.
public:
... };

CActuator actuator0(0);

I get errors when I try to construct a class variable with a parameter
inside CPlatform, but no error when I do the same just underneath it
(global variable).

What's going on?

Nothing. Learn C++. Read about constructors and initialiser lists.


Well, I have a lot of things to do.
Since I'm the tech guy in a startup company specialising in new VR tech I have
to be a Jack of All Trades. I'm doing the vision system (optics), motion control
(h/w electronic design and realtime s/w, plus mech), and audio DSP programming.
When we can afford a C++ coding monkey we'll get one.

Meanwhile, I'll ask around if I get a non-obvious (to me) problem.
Thanks.

--
Dirk

The Consensus:-
The political party for the new millenium
http://www.theconsensus.org
Dec 23 '05 #5
Dirk Bruere at Neopax wrote:
[..]
Well, I have a lot of things to do.
[..] When we can afford a C++ coding monkey we'll get
one.

Meanwhile, I'll ask around if I get a non-obvious (to me) problem.


Well, since you put it so nicely, I can only tell you to go have
a good holiday season. Best wishes from a C++ coding monkey.
Dec 23 '05 #6
Victor Bazarov wrote:
Dirk Bruere at Neopax wrote:
[..]
Well, I have a lot of things to do.
[..] When we can afford a C++ coding monkey we'll get
one.

Meanwhile, I'll ask around if I get a non-obvious (to me) problem.

Well, since you put it so nicely, I can only tell you to go have
a good holiday season. Best wishes from a C++ coding monkey.


And a merry Yuletime to you too:-)

--
Dirk

The Consensus:-
The political party for the new millenium
http://www.theconsensus.org
Dec 24 '05 #7
On Fri, 23 Dec 2005 22:10:35 +0000, Dirk Bruere at Neopax wrote:
Yes, it's Xmas and I'm working...

Got a problem (of course).
*****

class CPlatform
{
private:
CActuator actuator0(0);

public:
...
};

CActuator actuator0(0);

I get errors when I try to construct a class variable with a parameter inside
CPlatform, but no error when I do the same just underneath it (global variable).

What's going on?

thanks
Dirk

The Consensus:-
The political party for the new millenium
http://www.theconsensus.org

You can't initialize non static non-integer members inside the class
definition.

Your actuator is not static, so you should initialize it in the CPlatform
constructor:

CPlatform::CPlatform() : actuator0(0)
{
// more stuff in the constructor.
}
Dec 24 '05 #8
Hi,

Should work too, still I think mine is better ;-). Well there is less to
type and it might be more obvious for othere C++ developers. If you also
maintain the actutator class you might consider making the 0 the default
value for the constructor

class CAcutator
{
private:
unsigned long Number;
public:
CActuator( unsigned long Number = 0 ):
Number( Number )
{
}

Or something similar. Then you can forget about everything in the CPlatform
class

--
Regards, Ron AF Greve

http://moonlit.xs4all.nl

"Dirk Bruere at Neopax" <di*********@gmail.com> wrote in message
news:41*************@individual.net...
Moonlit wrote:
Hi,

You can't do it that way, you have to do it when constructing the class:

CPlatform::CPlatform():
actuator0(0)
{

}


In that case it might be more transparent to use the default constructor:

class CPlatform
{
private:
CActuator actuator0;

public:
CPlatform(){actuator0.SetNumber(0);}
};

Any problems doing it this way?

--
Dirk

The Consensus:-
The political party for the new millenium
http://www.theconsensus.org

Dec 24 '05 #9
Amadeus W. M. wrote:
On Fri, 23 Dec 2005 22:10:35 +0000, Dirk Bruere at Neopax wrote:

Yes, it's Xmas and I'm working...

Got a problem (of course).
*****

class CPlatform
{
private:
CActuator actuator0(0);

public:
...
};

CActuator actuator0(0);

I get errors when I try to construct a class variable with a parameter inside
CPlatform, but no error when I do the same just underneath it (global variable).

What's going on?

thanks
Dirk

The Consensus:-
The political party for the new millenium
http://www.theconsensus.org


You can't initialize non static non-integer members inside the class
definition.

Your actuator is not static, so you should initialize it in the CPlatform
constructor:

CPlatform::CPlatform() : actuator0(0)
{
// more stuff in the constructor.
}


Thanks.
Amadeus your real name?
Pretty good if so...
Dirk

The Consensus:-
The political party for the new millenium
http://www.theconsensus.org
Dec 24 '05 #10

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

Similar topics

1
by: Steve | last post by:
Hello, I'm encountering an unexpected behavior when using the "new" modifier in a derived class to hide an inherited base class property. I use "new" intentionally so I can change the Type of...
9
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
21
by: Jon Slaughter | last post by:
I have a class that is basicaly duplicated throughout several files with only members names changing according to the class name yet with virtually the exact same coding going on. e.g. class...
21
by: Mark Broadbent | last post by:
Consider the following statements //------- Item i = Basket.Items; //indexer is used to return instance of class Item Basket.Items.Remove(); //method on class item is fired item i = new...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
8
by: tshad | last post by:
I cannot seem to get the asp:textbox to use classes. Style works fine. I am trying to set the textbox to act like a label in some instance so it doesn't have a border, readonly and the background...
4
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project...
5
by: tony | last post by:
Hello! This is a rather long mail but it's a very interesting one. I hope you read it. I have tried several times to get an answer to this mail but I have not get any answer saying something...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
3
by: TamusJRoyce | last post by:
Hello. This is my first thread here. My problem has probably been came across by a lot of people, but tutorials and things I've seen don't address it (usually too basic). My problem is that I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.