user23993: 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 >= 0 && idx < 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 < NumLeds ; p++)
    {
      Pixels[p]=CRGB::Blue;
    }
}

Main Sketch:
for (int p = 0; p < 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 < 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?

user23993: 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]->Tick(millis());
...

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

23993: <p>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 <em>colors</em> (<code>Pixels[]</code>) 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 <strong><code>Pixels[]</code></strong> doesn't seem to match what I actually write in there.</p>

<p>Pattern.h:</p>

<pre><code>class Pattern
{
    public:
    CRGB PixelAt(int idx);
    CRGB Pixels[6];
}
</code></pre>

<p>Pattern.cpp:</p>

<pre><code>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;
  }
}
</code></pre>

<p>TestPattern.h:</p>

<pre><code>class TestPattern : public Pattern {
    void Tick(unsigned long millis);
}
</code></pre>

<p>TestPattern.cpp:</p>

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

<p>Main Sketch:</p>

<pre><code>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);
    }
  }
}
</code></pre>

<p>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.</p>

<p>So how should I declare and use <strong><code>Pixels[]</code></strong> so that the Main Sketch, the base class and the inherited class all have consistent information?</p>
 23993: <p>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 <a href="https://stackoverflow.com/questions/34681286/why-is-a-virtual-function-of-child-class-not-called">find the problem</a>.</p>

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

<pre><code>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());
...
</code></pre>

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

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

<pre><code>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());
...
</code></pre>

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