Go Down

Topic: Does Arduino have a problem with pointers to classes? (Read 1 time) previous topic - next topic

lloyddean

Preprocessing is an overloaded word and in the context I used refers to the IDE inserting the standard '#include <Arduino.h>' into your '.ino' file if you hadn't.  Adding function declarations you didn't following the last include file in the '.ino' that often interfere with your usage as in your case.

A few other things ...

PeterH


what's preprocessing?  XD)


The Arduino IDE is your problem.

There was nothing wrong with your code (that I could see). However, you have not explicitly included the declarations that would normally be required in code like that. In this case, due to the order in which you've defined your classes and functions, you didn't need to declare them in advance. However, the IDE has helpfully added declarations for you anyway. And it has screwed them up; it is the declaration for do_something_with_foo() helpfully added by the Arduino IDE which is causing the errors you encountered.

I don't understand the thinking behind the Arduino pre-processor at all. It's trying to make C++ behave a bit like Java. Which seems both pointless, and introducing needless complexity, as well as creating problems like this.
I only provide help via the forum - please do not contact me for private consultancy.

joe_weisman

Thanks guys. This forum was my last option before candles and chanting, but with your insight I now understand that it wasn't evil spirits after all. I didn't really mean to bother you to explain preprocessing, but thanks for demystifying the issues.

Nick Gammon

This compiles:

Code: [Select]

class event;
void queue_event(event *new_event_);

class event {
  public:
    int event_type;
    long time;
    event* next_event;   
};

void queue_event(event *new_event_) {
  // code to insert a new event into the queue will come here
};

void setup ()
  {

  }  // end of setup

void loop ()
  {
   
  }  // end of loop
 

lloyddean

Nick, that's really all my version does - it's a type  of forward declaration.

Go Up