compiler error "undefined reference for a template function" [duplicate]

  c++, templates

I’m a prof c# developper but I’m trying to write some code in C++ (for arduino purpose).
When I compile my code I have this error message "undefined reference to `NEOPATTERNController<(unsigned char)3, (EOrder)66>::SetPattern(PatternEnum)’"

this is my code:

-cpp file

#include <neopattern.h>

template<uint8_t DATA_PIN, EOrder RGB_ORDER >
void NEOPATTERNController<DATA_PIN, RGB_ORDER>::SetPattern(PatternEnum pattern) {
}

// No need to call this TemporaryFunction() function,
// it's just to avoid link error.
void TemporaryFunction ()
{
    NEOPATTERNController<1, GRB> TempObj;
}

-h file

#ifndef __INC_NEOPATTERN_H
#define __INC_NEOPATTERN_H

#include "FastLED.h"

// Pattern types supported:

typedef enum PatternEnum { NONE, RAINBOW_CYCLE, THEATER_CHASE, COLOR_WIPE, SCANNER, FADE, LIGHT, STROBE, NEWKITT };
 
template<uint8_t DATA_PIN, EOrder RGB_ORDER = GRB>
class NEOPATTERNController : public WS2812Controller800Khz<DATA_PIN, RGB_ORDER> {

public:
void SetPattern(PatternEnum pattern);
    
protected:

};

#endif
  • main code

NEOPATTERNController<DATA_PIN, GRB> patternController;
patternController.SetPattern(PatternEnum::RAINBOW_CYCLE);

I hope somebody can help, thanks.

Source: Windows Questions C++

LEAVE A COMMENT