error: 'CLASS' does not name a type only when creating object inside another object I'm trying to use Adafruit's LED Backpack library within a custom class. When I use the Adafruit library directly within a sketch, it compiles fine. When I use an example sketch provided with the library, it compiles fine. However when I create an instance of my custom class with the Adafruit object within it, I get the following error:


  In file included from sketch_feb18a.ino:6:
  /Users/lawnmowerlatte/Documents/Arduino/libraries/Bargraph/bargraph.h:18: error: 'Adafruit_24bargraph' does not name a type


All the reasons I've seen for this error stem from the library being missing or otherwise incorrectly installed. However, since I can use it directly, I think something else must be wrong.

Working

#include &lt;Adafruit_LEDBackpack.h&gt;
#include &lt;Adafruit_GFX.h&gt;
Adafruit_24bargraph bar = Adafruit_24bargraph();

void setup() { }
void loop() { }


Not Working

#include &lt;bargraph.h&gt;
Bargraph bargraph = Bargraph("Test", "api", 0);

void setup() { }
void loop() { }


bargraph.h

#ifndef Bargraph_h
#define Bargraph_h

#include &lt;Adafruit_GFX.h&gt;
#include &lt;Adafruit_LEDBackpack.h&gt;

#if (ARDUINO &gt;= 100)
#include &lt;Arduino.h&gt;
#else
#include &lt;WProgram.h&gt;
#endif

class Bargraph {
  public :
    String name;
    String api;
    Adafruit_24bargraph bar;

    Bargraph(String _name, String _api, int _device,
        String _type="Default");

    void set(String _value);
    void setMax(String _max);
    void update();
    void print();

  private :
    int display[24];

    long max;
    long value;
    int device;
    int size;
    String type;

    void format();
    void write();
};

#endif


bargraph.cpp

#define OFF 0
#define RED 1
#define YELLOW 2
#define GREEN 3

#include &lt;bargraph.h&gt;

#if (ARDUINO &gt;= 100)
#include &lt;Arduino.h&gt;
#else
#include &lt;WProgram.h&gt;
#endif

Bargraph::Bargraph(String _name, String _api, int _device, String _type) : bar() {
    name        = _name;
    api         = _api;
    max         = _max.toLong();
    device      = _device;
    type        = _type;
    value       = 0;

    for (int i=0; i&lt;24; i++) {
        display[i] = OFF;
    }

    bar.begin(0x70+device);
}

**Methods Omitted for Brevity**


Can anyone explain what's going on here? I'm pretty certain my class syntax is correct as I have other object-in-object relationships working. I can post code to GitHub if anyone would like to see more context.
I think these lines still need to be in your main sketch file (in addition to being in your custom class file):

#include &lt;Adafruit_LEDBackpack.h&gt;
#include &lt;Adafruit_GFX.h&gt;


If I remember the Arduino IDE quirks correctly, it uses the #include directives in the main sketch file to determine which libraries to actually link. It's one of those annoying features that was intended to be beginner-friendly but sometimes just makes things more confusing.