Unable to create member variables of my own object type.

**I put my code below.

I'm creating an LED Controller class that uses class objects that I have created. When I click verify, it states "field 'color' has incomplete type." in the RGBLed.h file for the field "Color color".

When I take "Color color;" and put it on top the RGBLed.cpp file as a global variable, it works verifys just fine. I am having the same issue with another class but don't want to put "Color color;" as a global in the cpp file. I want to have it in the public section of the .h file. I want the user to have access to it directly.

Anyone have any ideas?

Let me know if I made any sense.

Thanks beforehand.

Here's my code...

This is the RGBLed.h class I have created...

#ifndef RGB_LED_CLASS
#define RGB_LED_CLASS

class Color;

typedef unsigned char uint8_t;

class RGBLed
{
  private:
    uint8_t pin_r;
    uint8_t pin_g;
    uint8_t pin_b;
    Color color;
    boolean on;
  public:
    RGBLed(uint8_t pin_r, uint8_t pin_g, uint8_t pin_b, bool on);
    void SetColor(Color color);
    void SetColor(uint8_t r, uint8_t g, uint8_t b);
    void SetRed(uint8_t r);
    void SetGreen(uint8_t g);
    void SetBlue(uint8_t b);
    void SetLight(boolean on);
    boolean IsOn();
};

#endif

Here is the corresponding .cpp file.

#include "RGBLed.h"
#include "Color.h"

RGBLed::RGBLed(uint8_t pin_r, uint8_t pin_g, uint8_t pin_b, bool on)
{
  this->pin_r = pin_r;
  this->pin_g = pin_g;
  this->pin_b = pin_b;
  this->on = on;

  pinMode(pin_r, OUTPUT);
  pinMode(pin_g, OUTPUT);
  pinMode(pin_b, OUTPUT);

  SetColor(255,255,255);
  SetLight(on);
}

void RGBLed::SetColor(Color color)
{
  SetColor(color.r, color.g, color.b);
}
void RGBLed::SetColor(uint8_t r, uint8_t g, uint8_t b)
{
  SetRed(r);
  SetGreen(g);
  SetBlue(b);
}

void RGBLed::SetRed(uint8_t r)
{
  color.r = r;
}

void RGBLed::SetGreen(uint8_t g)
{
  color.g = g;
}

void RGBLed::SetBlue(uint8_t b)
{
  color.b = b;
}

void RGBLed::SetLight(boolean on)
{
  this->on = on;
  if(on)
  {
    analogWrite(pin_r, color.r);
    analogWrite(pin_g, color.g);
    analogWrite(pin_b, color.b);
  }
  else
  {
    analogWrite(pin_r, 0);
    analogWrite(pin_g, 0);
    analogWrite(pin_b, 0);
  }
}

boolean RGBLed::IsOn()
{
  return on;
}

And here is the actual Color.h

#ifndef COLOR_CLASS
#define COLOR_CLASS

typedef unsigned char uint8_t;

class Color
{
  public:
    Color();
    uint8_t r;
    uint8_t g;
    uint8_t b;
    void SetColor(Color color);
    void SetColor(uint8_t r, uint8_t g, uint8_t b);
};

#endif

And here is Color.cpp

#include "Color.h"

Color::Color()
{
  r = 255;
  g = 255;
  b = 255;
}

void Color::SetColor(Color color)
{
  SetColor(color.r, color.g, color.b);
}

void Color::SetColor(uint8_t r, uint8_t g, uint8_t b)
{
  this->r = r;
  this->g = g;
  this->b = b;
}

As a general suggestion, it is unwise to create a class with an obvious name like "Color", when there is quite likely to be another class which already has that name.

OK, well here is another answer.

In a particular source file, it is sometimes sufficient to name another class which is being referenced somewhere, without any details about it. Sometimes.

So where you have the line

class Color ;

it is telling the compiler that there is a reference to some class called Color, which the compiler won't need to know any details about while compiling this particular source code file.

On the other hand

include "Color.h"

will provide the compiler with access to the full specification of the Color class.

The place where the compiler is objecting, it requires more information about the Color class than the mere notification that such a class exists, which is what you have provided.

The solution is probably to add #include "Color.h" in that source file where the error occured.

The solution is probably to add #include "Color.h" in that source file where the error occured.

It is. When you create an instance of the RGBLed class, all that is known is that Color is a class. There is not enough known about color to be able to create an instance of the Color class so that he RGBLed class can be instantiated.