Arduino C++ - 尝试实例化具有非类型模板参数的类时出错
Arduino C++ - Error when trying to instantiate class which has non-type template parameter
这是我尝试实例化"Melodie"对象的文件:
#include <Melodie.h>
Melodie<5> m(8);
void setup()
{
}
void loop()
{
}
这是"Melodie.h"文件:
#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
我收到以下错误消息:错误:"<"标记之前的预期构造函数、析构函数或类型转换
为什么?相同的代码在Visual Studio中工作(减去arduino特定的东西)。我以为 WinAVR 支持C++?
我尝试编译您的代码 (GCC),没有问题,进行了两个小的修改。
- 将
#include <Melodie.h>
更改为#include "Melodie.h"
-
注释掉以下内容
//#include <Arduino.h> //#include "pitches.h"
因为它们没有被使用。
相关文章:
- 为 NewObjectA() 函数创建 jvalues 的参数数组时出错 - JNI Invocation API
- 将成员函数作为构造函数参数调用时出错 "Variable is not a type name"
- 使用一个参数的模板函数时出错(适用于 2)
- 为什么在函数参数前面添加 const 会出错?
- 变量用作C中的函数参数后出错
- 将私有数据成员作为默认参数传递给该类的公共方法时出错
- 使用 cvThreshold 时报告参数时出错
- STL 容器在函数中作为模板参数,在调用中出错
- 使用模板模板参数时出错
- 方法的参数列表出错
- 将 std::bind 应用于带有参数 <boost::asio::ip::tcp::socket> 时出错?
- 使用模板函数传递模板参数时出错
- 在 c++ 中调用将字符串作为参数传递的函数时出错
- 在运算符中将联合作为参数传递时出错<<
- 在C 中使用Caffe;无法将Caffe ::求解参数仪发挥作用而不会出错
- 尝试使用浮点参数运行重载函数时出错
- 尝试将 C++11 代码转换为 C++03 时默认函数模板参数出错
- Lua c++ lib sethook:钩子函数参数出错
- 在 Unix 中编译 c++ 时嵌套模板参数出错
- uniform_real_distribution c++的最小/最大参数出错