Compile error with separate header/implementation files

I’m having problems with the arduino compiler throwing a compilation error only when I have separate implementation & header files. If I put the entire class in one file, it compiles fine.

Is there some trick to make this work right?

Header file:

class emon{
  public:
  ads testads;
  void init(ads &theads);
  void calculate();
};

Implementation File:

#include "emon.h"

void emon::init(ads &theads){
  this->testads = theads;
}
void emon::calculate(){
  this->testads.getVal(2);
}

Sketch

class ads{
  public:
  int getVal(int pin){
    return pin * 2;
  }
};

#include "emon.h"


ads myads;
emon myemon;

void setup(){
  myemon.init(myads);
}

void loop(){
  myemon.calculate();
}

If I try to compile that, I will get an error: emon.h:3: error: ‘ads’ does not name a type

Note that my ads class is declared BEFORE the emon class, so the error seems to be bogus to me…

I’ve tracked it down to the .cpp file including the header. If I put the whole class definition in the header file it compiles just fine.

Is there any way around this? Or do I just have to put all my code in one file and move on with life?

"emon.cpp" doesn't know what "ads" is. You didn't include its definition.

Pieter