Referencing an object into a class

12 Oct 2010

Hi.

I'm trying to make a class that has the ability to reference an object. I'm getting some errors now that I can't fix myself with google, atleast not with my search inquiries.

I'll post my quick'n'dirty code.

main.cpp:

#include "mbed.h"
#include "leds.h"
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);

int main() {
    //experimental code:
   leds LedClass(led1, led2, led3, led4);
}

leds.cpp:

#include "mbed.h"
#include "leds.h"

leds::leds(const DigitalOut& l1, const DigitalOut& l2, const DigitalOut& l3, const DigitalOut& l4){
    wait_ms(200);
    l1=1;
}

leds.h:

#ifndef MBED_LEDS_H
#define MBED_LEDS_H

#include "mbed.h"
class leds {
public:
    leds(const DigitalOut& l1, const DigitalOut& l2, const DigitalOut& l3, const DigitalOut& l4);
    
};
#endif


I hope I remembered all the relevant code. Anyways. This doesnt work. It gives me the following errors

"No operator "=" matches these operands (E349)" in file "LEDS/leds.cpp"

and

"        ^ (E0)" in file "LEDS/leds.cpp"

This is my first try to reference an object into a class. How could I make this work?

Thanks

13 Oct 2010

I guess I figured this out myself. It was only necassary to remove "const", and just have the following code

#include "mbed.h"
#include "leds.h"

leds::leds(DigitalOut& l1, DigitalOut& l2, DigitalOut& l3, DigitalOut& l4){
    wait_ms(200);
    l1=1;
}

Well, it's compiling without errors now. I'm not able to test this in practice right now, but I guess it should work allright. I feel a little bit stupid, but hey, as long as it's learning it's all good.