Go Down

Topic: HardwareSerial (Read 1 time) previous topic - next topic

stauffski

I'm stumped by the stack trace. I can't figure out what's wrong with the code. I even slept on it. I removed all the bulk of the library and left only the parts in .h and .cpp that are causing the error. Does anybody see it?

LCD.h
Code: [Select]

#ifndef LCD_h
#define LCD_h

#include "WProgram.h"

class LCD
{
public:
  LCD();
  LCD(HardwareSerial LCDHardwareSerial);
  HardwareSerial hardwareSerial;
};
#endif


LCD.cpp
Code: [Select]

#include "WProgram.h"
#include "LCD.h"

HardwareSerial hardwareSerial;

LCD::LCD()
{
  hardwareSerial = Serial;
  hardwareSerial.begin(9600);
}

LCD::LCD(HardwareSerial LCDHardwareSerial)
{
  hardwareSerial = LCDHardwareSerial;
  hardwareSerial.begin(9600);
}


Stack trace
Code: [Select]

C:\Program Files\Arduino\libraries\LCD\LCD.cpp:10: error: no matching function for call to 'HardwareSerial::HardwareSerial()'
C:\Program Files\Arduino\hardware\arduino\cores\arduino/HardwareSerial.h:50: note: candidates are: HardwareSerial::HardwareSerial(ring_buffer*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)
C:\Program Files\Arduino\hardware\arduino\cores\arduino/HardwareSerial.h:32: note:                 HardwareSerial::HardwareSerial(const HardwareSerial&)
C:\Program Files\Arduino\libraries\LCD\LCD.cpp: In constructor 'LCD::LCD()':
C:\Program Files\Arduino\libraries\LCD\LCD.cpp:12: error: no matching function for call to 'HardwareSerial::HardwareSerial()'
C:\Program Files\Arduino\hardware\arduino\cores\arduino/HardwareSerial.h:50: note: candidates are: HardwareSerial::HardwareSerial(ring_buffer*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)
C:\Program Files\Arduino\hardware\arduino\cores\arduino/HardwareSerial.h:32: note:                 HardwareSerial::HardwareSerial(const HardwareSerial&)
C:\Program Files\Arduino\libraries\LCD\LCD.cpp: In constructor 'LCD::LCD(HardwareSerial)':
C:\Program Files\Arduino\libraries\LCD\LCD.cpp:18: error: no matching function for call to 'HardwareSerial::HardwareSerial()'
C:\Program Files\Arduino\hardware\arduino\cores\arduino/HardwareSerial.h:50: note: candidates are: HardwareSerial::HardwareSerial(ring_buffer*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)
C:\Program Files\Arduino\hardware\arduino\cores\arduino/HardwareSerial.h:32: note:                 HardwareSerial::HardwareSerial(const HardwareSerial&)


Thanks,
Stauffski

That's not a stack trace, that's a linker compiler error.

This line:

Code: [Select]
HardwareSerial hardwareSerial;

Calls the default constructor for HardwareSerial which takes no arguments. However the HardwareSerial class has no such constructor.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

jwatte


I'm stumped by the stack trace. I can't figure out what's wrong with the code. I even slept on it. I removed all the bulk of the library and left only the parts in .h and .cpp that are causing the error. Does anybody see it?




I see several problems.

1) You should pass the HardwareSerial argument by reference (using a & sign) to avoid copying
2) You should declare the HardwareSerial class member as a reference, so it references back to the original global (again using a & sign)
3) You should pass the necessary arguments to the constructor of the HardwareSerial class.


PaulS

Quote
3) You should pass the necessary arguments to the constructor of the HardwareSerial class.

No. The HardwareSerial class already creates all the valid instances of HardwareSerial, as Serial, Serial1, Serial2, and Serial3. There should be no calls to the HardwareSerial class' constructor.

Go Up