2
votes

Here's the file where in which I try to instantiate the "Melodie" object:

#include <Melodie.h>

Melodie<5> m(8);

void setup()
{

}

void loop()
{

}

Here's the "Melodie.h" file:

#ifndef Melodie_H
#define Melodie_H

#include <Arduino.h>
#include "pitches.h"

template <int NB_NOTES>
class Melodie
{
public:
    Melodie(int pin)
    {
        // Some unimportant stuff
    }
    void addNote(int pitch, int duration)
    {
        // Some unimportant stuff
    }
    void play()
    {
        // Some unimportant stuff
    }

private:
    char notes_[NB_NOTES];
    char durations_[NB_NOTES];
    int  notePointer_;
    int  pin_;
};

#endif

I get the following error message: error: expected constructor, destructor, or type conversion before '<' token

Why? The same code works(minus arduino specific stuff) works in Visual Studio. I thought WinAVR supported C++?

1
That error messages comes with a file name, line number and position number. Please add them to your question and mark the relevant spot in your code.us2012
+1 For those who are curious, the line with the error is Melodie<5> m(8);. Looking for an answer to this question as well.Zak
I ended up not using templates at all, unfortunately :(Michael

1 Answers

-1
votes

I tried and compiled your code (GCC) without problem with two minor modifications.

  1. Change #include <Melodie.h> to #include "Melodie.h"
  2. comment out the following

    //#include <Arduino.h>
    
    //#include "pitches.h"
    

since they are not used.