0
我正在研究Arduino,並且想要製作一個小型玩具鋼琴。爲了練習,我創建了我自己的叫做map的類。Visual Studio 2013上的C++ Arduino 1.6
#ifndef Map_h
#define Map_h
#include "Arduino.h"
template <class Key, class Value> class Map
{
public:
Map();
~Map();
void add(Key key, Value value);
Value find(Key key);
private:
Key *keys;
Value *values;
int size;
bool resize();
};
#endif
在主我只是把它正常:
Map<char, int> *name_to_freq = new Map<char, int>();
name_to_freq->add('c', 262);
但我得到了一些錯誤,當編譯。
ccQwtG4w.ltrans0.ltrans.o*: In function main
ccQwtG4w.ltrans0.o*: (.text.startup+0x354): undefined reference to Map<char, int>::Map()
ccQwtG4w.ltrans0.o*: (.text.startup+0x3de): undefined reference to Map<char, int>::add(char, int)
定義在.cpp文件:
是否有任何人之前看到這一點,知道如何解決它?
template <typename Key, typename Value>
Map<Key, Value>::Map()
{
keys = new Key[defaultArraySize];
values = new Value[defaultArraySize];
size = defaultArraySize;
}
template <typename Key, typename Value>
void Map< Key, Value>::add(Key key, Value value)
{
for (int i = 0; i < size; i++)
{
if (!keys[i])
{
keys[i] = key;
values[i] = value;
if (i >= size/2)
{
while (!resize());
}
}
}
}
哪裏是你的地圖(定義),並添加() ? –
一秒鐘....添加 –
是定義在源文件(cpp文件)上? –