C++ problem with classes


hey there,

i'm doing first steps in programming c++. succeed in making class worked when wrote litlle test it. class called "analoog"
now want use objects class make class, called licht. don't know why, everytime want build librarie gives errors:
quote
"licht.cpp:27: error : '((licht*)this -> licht::seconde' not have class type"

"licht.cpp:32: error : '((licht*)this -> licht::groen' not have class type"

and

"licht.cpp:33: error : '((licht*)this -> licht::rood' not have class type"



i'm thinking there's wrong way i'm initialising class objects... tried many things, gave errors.
does see i'm doing wrong?

this header-file (.h) :

code: [select]

/*
auteur : bo knooren
*/
#ifndef licht_h
#define licht_h

#include "wconstants.h"

#include <metro.h>

#include <analoog.h>

class licht
{
public:
licht();
boolean vangroennaarrood(int tijd, int aantalstappen);
private:
analoog groen(int a);
analoog rood(int b);
metro seconde(int c); // houdt een 1 bij wanneer 1 seconde gepasseerd

int counter; // telt de seconden
int teller; // telt de het aantal keer dat de leds een beetje van kleur veranderd zijn
};


#endif





this source file (.cpp) :

code: [select]

/*
auteur : bo knooren
*/

#include "wprogram.h"
#include "licht.h"

licht::licht()
{
metro seconde(1000);
analoog groen(3);
analoog rood(5);
counter = 0;
teller = 1;
}


/** zal elke keer dat t wordt opgeroepen controleren of het rood en groen moet veranderen en dat dan doen
* tijd in seconden, 85 stappen aangeraden
* veronderstelt dat groen licht al aan en rood licht uit is
* geeft true als hij klaar is, false als hij nog niet klaar is
*/
boolean licht::vangroennaarrood(int tijd, int aantalstappen)
{
if(aantalstappen > 255) aantalstappen = 255;
if((metro) seconde.check() == 1) // seconde voorbij?
{
counter++; // seconde bijtellen
if(counter == tijd/aantalstappen*teller) // hit, hij moet veranderen
{
(analoog) groen.increment(-255/aantalstappen);
(analoog) rood.increment(255/aantalstappen);
teller++;
}
}

if(counter == tijd) // hij heeft gedaan met faden
{
counter = 0; //counter terug instellen op startwaarde
teller = 1; //teller terug instellen op startwaarde
return true;
}
else return false;
}

this line in class declaration:
code: [select]

analoog groen(int a);


declares groen instance method taking single int parameter , returning instance of class analoog.

this line, in class definition:
code: [select]

analoog groen(3);


is little unusual given above, can't tell it's doing, looks you're trying initialise instance variable calling constructor, in case should rewrite header declaration read:

code: [select]

analoog groen;  // declare instance variable of type analoog.


the same true seconde , rood.

then change definition of constructor read:

code: [select]

licht::licht()
: seconde(1000), groen(3), rood(5), counter(0), teller(1)
{
}


i suggest read little more on class declarations, particularly how instance variables , methods declared , initialised.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > C++ problem with classes


arduino

Comments