I'm using mthreads (https://github.com/jlamothe/mthread) for my arduino. But now as the project is getting bigger, it would make sense to break it up in several files.
I successfully outsourced already a part which is not threaded. But somehow I cannot make up my mind how to use mthread in conjunction with several header files.
here is what I got:
main: call header:
#include "tcan.h"
tcan.h:
#ifndef tcan_h
#define tcan_h
#include "Arduino.h"
class tcan : public Thread {
public: tcan();
protected: bool loop();
private:
};
#endif
tcan.cpp
#include "Arduino.h"
#include "tcan.h"
#include <mcp_can.h>
bool tcan::loop() {
// lala
return true;
}
but I get an error when compiling:
tcan.h:6:28: error: expected class-name before '{' token class tcan : public Thread {
Thanks in advance
-
Check for circular #includes... The error can be caused by including Arduino.h twice.user3704293– user37042932016年01月27日 07:46:54 +00:00Commented Jan 27, 2016 at 7:46
1 Answer 1
The compiler error is due to that the compiler does not know what Thread is.
tcan.h:6:28: error: expected class-name before '{' token class tcan : public Thread {
The issue is that the header file is not complete. A good practice is to include all header files that are needed to read the header file. As Thread is defined in mthread.h the tcan.h file should be:
#ifndef tcan_h
#define tcan_h
#include <mthread.h>
class tcan : public Thread {
public: tcan();
protected: bool loop();
private:
};
#endif
Cheers!
-
that was the right hint "Assuming that Thread is defined in mcp_can.h". Of course I need to include "<mthread.h>". Thanks for the hint! It's working now.jblaze– jblaze2016年01月27日 08:53:22 +00:00Commented Jan 27, 2016 at 8:53
-
Great! I will update the answer with the correct include.Mikael Patel– Mikael Patel2016年01月27日 09:14:39 +00:00Commented Jan 27, 2016 at 9:14