I am experiencing some weirdness… I have 2 files foo.ino and bar.h using the Particle Dev IDE. Everything compiles fine until I move the implementation of one of my private methods from the .h file to a newly created .cpp file. The first error is ‘uint16_t has not been declared’ - which happens to be one of the args to my constructor in the .h file. There’s a long list of errors where I’m using other standard types also, the uint16_t just happens to be the first.
foo.ino
#include "bar.h"
Bar bar((const char[]){ 10, 1, 1, 1 }, 8080);
void setup() { }
void loop() { bar.doStuff(); }
bar.h
#ifndef _bar_
#define _bar_
class Bar
{
public:
Bar(const char * host, uint16_t port) : host(host), port(port) { }
void doStuff() { baz(); }
private:
bool baz();
const char * host;
uint16_t port;
};
#endif
bar.cpp
#include "bar.h"
bool Bar::baz()
{
return true;
}
As I mentioned, if I delete the cpp file and move the implementation of baz() to bar.h, everything works fine. Also, if I add #include <stdint.h>
to the top of bar.h it compiles with the cpp file. While I can obviously work around this, I wouldn’t mind knowing:
- why this is happening (or is it just me being pedantic)
- am I doing something less than ideal by adding the stdint include to work around the problem
- what should I be doing different, if anything
Oh yeah, and adding #pragma SPARK_NO_PREPROCESSOR
to the top of my ino file doesn’t change anything, if that helps.
Many thanks