Pass custom element of an array from an inherited class to main sketch I'm building a base class that creates color patterns using FastLed's CRGB structure. I use the base class as inheritance for another more specific class that modifies a vector of colors (Pixels[]) and at some point I want to pass the color of a specific element from my class to the main sketch. But i'm having some issues with it, since the content of Pixels[] doesn't seem to match what I actually write in there.

Pattern.h:

class Pattern
{
    public:
    CRGB PixelAt(int idx);
    CRGB Pixels[6];
}


Pattern.cpp:

CRGB Pattern::PixelAt(int idx) 
{
  // safety check
  if (idx &gt;= 0 &amp;&amp; idx &lt; NumLeds)
  {
    return Pixels[idx];
  }
  else
  {
    Serial.print("Index out of bounds: "); Serial.println(idx);
    return CRGB::Black;
  }
}


TestPattern.h:

class TestPattern : public Pattern {
    void Tick(unsigned long millis);
}


TestPattern.cpp:

void TestPattern::Tick(unsigned long millis)
{
    for (int p = 0 ; p &lt; NumLeds ; p++)
    {
      Pixels[p]=CRGB::Blue;
    }
}


Main Sketch:

for (int p = 0; p &lt; NUM_PATTERNS; p++)
{
  // update pattern
  ledPatterns[p].Tick(millis());

  if (ledPatterns[p].Status == Enabled)
  {
    // sum the values of the pixels
    for (int l = 0; l &lt; NUM_LEDS; l++) {
      leds[l] += ledPatterns[p].PixelAt(l);
    }
  }
}


I'm skipping parts of the code to make it easier to read, but I think with this much you should be able to help me make it work. I'm still getting acquainted with C and pointers, which is where I think the problem lies.

So how should I declare and use Pixels[] so that the Main Sketch, the base class and the inherited class all have consistent information?
After reading comments i got some more clues where to search and indeed the problem was somewhat in the inheritance and how i was calling the functions. This post helped me find the problem.

I forgot to post the piece of code where i was creating the patterns in the Main Sketch, this is how it was initially:

Pattern ledPatterns[NUM_PATTERNS];
ledPatterns[0] = TestPattern(NUM_LEDS, "Test Pattern 1", TestPat, 0, 0);
ledPatterns[1] = TestPattern(NUM_LEDS, "Test Pattern 2", TestPat, 0, 1);

...
ledPatterns[p].Tick(millis());
...


When i later called ledPatterns.Tick (the function that modifies the values, the function actually being called was the parent and not the child. Thus the unexpected result.

This is how i should have been initializing the patterns, since they are inherited:

Pattern* ledPatterns[NUM_PATTERNS];
ledPatterns[0] = new TestPattern(NUM_LEDS, "Test Pattern 1", TestPat, 0, 0);
ledPatterns[1] = new TestPattern(NUM_LEDS, "Test Pattern 2", TestPat, 0, 1);

...
ledPatterns[p]-&gt;Tick(millis());
...


Sorry for the huge confusion, i thought the problem was in a completely different part of the code