I am using this function to copy one vector to the end of another:
template <typename T, typename U>
void addVectorToVector(std::vector<T>* oldVector, std::vector<U> input){
for(uint8_t i = 0; i < Input(size); i++){
T inputVar = (T) Input[i];
oldVector->push_back(inputVar);
}
return;
}
This throws a compilation error in Arduino IDE:
C:\Users\ehle_ta\AppData\Local\Temp\arduino_build_330682\sketch\main.ino.cpp.o: In function `std::vector<unsigned char, std::allocator<unsigned char> >::_M_check_len(unsigned int, char const*) const':
c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\bits/stl_vector.h:1425: undefined reference to `std::__throw_length_error(char const*)'
collect2.exe: error: ld returned 1 exit status
I can tell that the error dissappears when I comment out
oldVector->push_back(inputVar);
but I don't get why does this link error happen.
edit:
The error can be triggered by compiling this code:
#include <vector>
void setup() {
std::vector<unsigned char> vector1;
std::vector<unsigned char> vector2;
vector2.push_back(0x01);
vector2.push_back(0x02);
addVectorToVector(&vector1, vector2);
}
// add the content of a vector to the end of another vector
template <typename T, typename U>
void addVectorToVector(std::vector<T>* oldVector, std::vector<U> input){
for(uint8_t i = 0; i < input.size(); i++){
T inputVar = (T) input[i];
oldVector->push_back(inputVar);
}
return;
}
Is there an error in my implementation/use of vector::push_back or is possible that the std::vector class I'm using isn't the Standard C++11 one and therefore causes problems?