Help With Setting Up Delegates

Hello everyone,

So I am having a trouble setting up my delegates in a piece of code I am writing. I am trying to find answers online, but am getting no where.

I should point out that C++ is probably one of my weakest languages (much stronger in items such as C#), so please forgive me if this seems trivial. Anyway I have the following code I am working on so far (well a snippet, I removed code unrelated to the issue)

#include <Adafruit_NeoPixel.h>

/// <summary>
/// 
/// </summary>
class NeoPixelPattern
{
  private:void (*SetPixelCallback) (int, uint32_t, bool);
  private:void (*ShowCallback) ();

  /// <summary>
  /// 
  /// </summary>
  public:NeoPixelPattern()
  {
	
  }

  /// <summary>
  /// 
  /// </summary>
  /// <param name="numPixels"></param>
  /// <param name="color1"></param>
  /// <param name="color2"></param>
  /// <param name="steps"></param>
  /// <param name="interval"></param>
  /// <param name="setPixelCallback"></param>
  /// <param name="showCallback"></param>
  public:NeoPixelPattern(uint16_t numPixels, uint32_t color1, uint32_t color2, uint16_t steps, uint8_t interval, void (*setPixelCallback) (int, uint32_t, bool), void (*showCallback) ())
  {
    this->SetPixelCallback = setPixelCallback;
    this->ShowCallback = showCallback;
  }

  /// <summary>
  /// 
  /// </summary>
  /// <param name="index"></param>
  /// <param name="color"></param>
  /// <param name="gammaCorrection"></param>
  protected:virtual void OnSetPixel(int index, uint32_t color, bool gammaCorrection)
  {
    if(SetPixelCallback != NULL)
    {
      SetPixelCallback(index, color, gammaCorrection);
    }
  }

  /// <summary>
  /// 
  /// </summary>
  protected:virtual void OnShow()
  {
    if(ShowCallback != NULL)
    {
      ShowCallback();
    }
  } 
};

enum class Direction { NONE, FORWARD, REVERSE };

/// <summary>
/// 
/// </summary>
class FadeNeoPixelPattern: public NeoPixelPattern
{
  /// <summary>
  /// 
  /// </summary>
  FadeNeoPixelPattern(): ()
  {

  }
  
  /// <summary>
  /// 
  /// </summary>
  /// <param name="colorFrom"></param>
  /// <param name="colorTo"></param>
  /// <param name="steps"></param>
  /// <param name="interval"></param>
  /// <param name="setPixelCallback"></param>
  /// <param name="showCallback"></param>
  /// <param name="startDirection"></param>
  public:FadeNeoPixelPattern(uint16_t numPixels, uint32_t colorFrom, uint32_t colorTo, uint16_t steps, uint8_t interval, void (*setPixelCallback) (int, uint32_t, bool), void (*showCallback) (), Direction startDirection): NeoPixelPattern(numPixels, colorFrom, colorTo, steps, interval, setPixelCallback, showCallback)
  {

  }
};

/// <summary>
/// 
/// </summary>
class BaseNeoPixels: public Adafruit_NeoPixel
{
  private:NeoPixelPattern SetPatterns [2];
  
  /// <summary>
  /// 
  /// </summary>
  /// <param name="pixels"></param>
  /// <param name="pin"></param>
  /// <param name="type"></param>
  public:BaseNeoPixels(uint16_t pixels, uint8_t pin, uint8_t type): Adafruit_NeoPixel(pixels, pin, type)
  {
    this->SetPatterns[0] = FadeNeoPixelPattern(144, Color(0,0,0), Color(255,138,0), 100, 5, &SetPixelCall, &ShowCall, Direction::FORWARD);
  }

  /// <summary>
  /// 
  /// </summary>
  /// <param name="index"></param>
  /// <param name="color"></param>
  /// <param name="gammaCorrection"></param>
  private:void SetPixelCall(int index, uint32_t color, bool gammaCorrection)
  {
    
  }

  /// <summary>
  /// 
  /// </summary>
  private:void ShowCall()
  {
    
  }
  
};

void setup() 
{
  // put your setup code here, to run once:

}

void loop() 
{
  // put your main code here, to run repeatedly:

}

In the BaseNeoPixels constructor, when trying to set the first index of the array I get the following error

no matching function for call to ‘FadeNeoPixelPattern::FadeNeoPixelPattern(int, uint32_t, uint32_t, int, int, void (BaseNeoPixels::)(int, uint32_t, bool), void (BaseNeoPixels::)(), Direction)’

From what I can tell this is because I don’t specify the class like so void (BaseNeoPixels::*setPixelCallback) (int, uint32_t, bool)

in the constructor for the “FadeNeoPixelPattern”

The only problem is when I try that I get the error

expected ‘)’ before ‘::’ token

I’m at a lose here. As I mentioned C++ isn’t my strongest, as I never needed to develop in it before. So really I am stepping into a lot of new territories, and could use some help (I am actually doing this to help a friend with a cosplay project of theirs).

Thanks!

  FadeNeoPixelPattern(): ()
  {

  }

What do you think this is doing?

PaulS:

  FadeNeoPixelPattern(): ()

{

}



What do you think this is doing?

I left that so I could create an array without initializing its elements right away. If I set both those delegate values to NULL, this throws no error

The point is that after the colon is where you assign values to fields or invoke other (base class or member) constructors. The parentheses floating there are wrong.

I left that so I could create an array without initializing its elements right away.

I don't see how the parentheses relate to creating an array. You can't create an array that way. You have to declare that the class contains an array of some type in the class definition.

Oh I see what you are getting that. Those are there because that class is a derived from the NeoPixelPattern class

class FadeNeoPixelPattern: public NeoPixelPattern

The rest I assume is pretty self-explanatory

Those are there because that class is a derived from the NeoPixelPattern class

That the class derives from another is not why the parentheses are there. They would be there if you needed to construct the base class, but if you needed to do that you'd have the name of the base class in front of them (to explicitly invoke its constructor).

The compiler is clearly telling you that the parentheses do not belong there.