6 years, 9 months ago.

Serial class as a member of my custom class

Hello, I have a problem with inicilization of class in another class. Here is my constructor:

PpmIn::PpmIn(PinName pin): ppm(pin), pc_com(USBTX, USBRX)
{
    pc_com.printf("Constructor say hi!");
    current_channel = 0;
    ...

pc_com is initialized in header file like this:

protected:
        Serial pc_com;
        InterruptIn ppm;
...

I think, that there shouldn't be a problem, but I always end with this error: Error: "mbed::Stream::Stream(const mbed::Stream &)" (declared at /extras/mbed-os.lib/drivers/Stream.h:68 is inaccessible in "extras/mbed-os.lib/drivers/Serial.h", Line: 52, Col: 43

Similar problem was discussed here: https://developer.mbed.org/forum/helloworld/topic/2771/

It seems, that I can't access constructor in mbed::Stream? Really? Do you know how to get over this? Thank you very much.

edy05

1 Answer

6 years, 9 months ago.

Hello Eduard,

That's strange because the following compiled for me with no errors:

PpmIn.h

#include "mbed.h"

class PpmIn
{
public:
    PpmIn(PinName pin);
    
protected:
    InterruptIn  ppm;
    Serial       pc_com;
};

PpmIn.cpp

#include "PpmIn.h"

PpmIn::PpmIn(PinName pin): ppm(pin), pc_com(USBTX, USBRX) {
    pc_com.printf("Constructor say hi!");
}

main.cpp

#include "mbed.h"
#include "PpmIn.h"

PpmIn myPpm(PA_9);

int main(void) {
    while(1) {}
}

Did you include the header files?

Accepted Answer

Strange. Could you please look at the full code here? https://developer.mbed.org/users/edy05/code/pwm-output/ I don't see any difference there.

posted by Eduard Medla 09 Jun 2017

Hello,
It seems that you are using the same name for the PinName ppmIn (line #7) as for the PpmIn ppmIn object (line #25). The code compiles smoothly after commenting out line #7, uncommenting line #18 and modifying line #25 as follows:

    PpmIn ppmIn(D14);
posted by Zoltan Hudak 09 Jun 2017

Hello Zoltan, Yes, now it work, thank you

posted by Eduard Medla 13 Jun 2017