Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 23rd, 2005, 10:25 PM
Dirk Bruere at Neopax
Guest
 
Posts: n/a
Default 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
  #2  
Old December 23rd, 2005, 10:55 PM
Moonlit
Guest
 
Posts: n/a
Default Re: Class in class problem

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" <dirk.bruere@gmail.com> wrote in message
news:413aupF1d50jmU1@individual.net...[color=blue]
> 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[/color]


  #3  
Old December 23rd, 2005, 11:05 PM
Victor Bazarov
Guest
 
Posts: n/a
Default Re: Class in class problem

Dirk Bruere at Neopax wrote:[color=blue]
> Yes, it's Xmas and I'm working...[/color]

It's not Xmas yet.
[color=blue]
> Got a problem (of course).
> *****
>
> class CPlatform
> {
> private:
> CActuator actuator0(0);[/color]

This is an attempt to initialise a non-static member where there can be no
initialiser. Read about initialising members properly.
[color=blue]
> 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?[/color]

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

V
  #4  
Old December 23rd, 2005, 11:25 PM
Dirk Bruere at Neopax
Guest
 
Posts: n/a
Default Re: Class in class problem

Moonlit wrote:
[color=blue]
> Hi,
>
> You can't do it that way, you have to do it when constructing the class:
>
> CPlatform::CPlatform():
> actuator0(0)
> {
>
> }
>[/color]

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
  #5  
Old December 23rd, 2005, 11:35 PM
Dirk Bruere at Neopax
Guest
 
Posts: n/a
Default Re: Class in class problem

Victor Bazarov wrote:
[color=blue]
> Dirk Bruere at Neopax wrote:
>[color=green]
>> Yes, it's Xmas and I'm working...[/color]
>
>
> It's not Xmas yet.
>[color=green]
>> Got a problem (of course).
>> *****
>>
>> class CPlatform
>> {
>> private:
>> CActuator actuator0(0);[/color]
>
>
> This is an attempt to initialise a non-static member where there can be
> no initialiser. Read about initialising members properly.
>[color=green]
>> 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?[/color]
>
>
> Nothing. Learn C++. Read about constructors and initialiser lists.[/color]

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
  #6  
Old December 23rd, 2005, 11:55 PM
Victor Bazarov
Guest
 
Posts: n/a
Default Re: Class in class problem

Dirk Bruere at Neopax wrote:[color=blue]
> [..]
> 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.[/color]

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.
  #7  
Old December 24th, 2005, 12:05 AM
Dirk Bruere at Neopax
Guest
 
Posts: n/a
Default Re: Class in class problem

Victor Bazarov wrote:
[color=blue]
> Dirk Bruere at Neopax wrote:
>[color=green]
>> [..]
>> 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.[/color]
>
>
> 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.[/color]

And a merry Yuletime to you too:-)

--
Dirk

The Consensus:-
The political party for the new millenium
http://www.theconsensus.org
  #8  
Old December 24th, 2005, 03:15 AM
Amadeus W. M.
Guest
 
Posts: n/a
Default Re: Class in class problem

On Fri, 23 Dec 2005 22:10:35 +0000, Dirk Bruere at Neopax wrote:
[color=blue]
> 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[/color]


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


  #9  
Old December 24th, 2005, 10:25 AM
Moonlit
Guest
 
Posts: n/a
Default Re: Class in class problem

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" <dirk.bruere@gmail.com> wrote in message
news:413eigF1d1mtfU1@individual.net...[color=blue]
> Moonlit wrote:
>[color=green]
>> Hi,
>>
>> You can't do it that way, you have to do it when constructing the class:
>>
>> CPlatform::CPlatform():
>> actuator0(0)
>> {
>>
>> }
>>[/color]
>
> 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[/color]


  #10  
Old December 24th, 2005, 01:55 PM
Dirk Bruere at Neopax
Guest
 
Posts: n/a
Default Re: Class in class problem

Amadeus W. M. wrote:
[color=blue]
> On Fri, 23 Dec 2005 22:10:35 +0000, Dirk Bruere at Neopax wrote:
>
>[color=green]
>>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[/color]
>
>
>
> 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.
> }[/color]

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


Dirk

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

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles