Hi!
I'm trying to make use of a <vector> defined in an external .h library,
but that throws an error at compile time:
I've stripped the code down as much as I could, and experimented with it, but to no success.
What puzzles me is that the vector defined within .ino file does want to 'resize' without troubles,
but the one defined in ABC.h makes trouble.
Could someone please explain what am I doing wrong. Thank you!
The code looks like this:
TEST_vector.ino
ABC.cpp
ABC.h
I'm trying to make use of a <vector> defined in an external .h library,
but that throws an error at compile time:
/var/folders/zh/bzyv3r3x00540nsr8zgwpvrh0000gp/T/arduino_build_4613/sketch/TEST_vector.ino.cpp.o: In function `std::vector<double, std::allocator<double> >::_M_check_len(unsigned int, char const*) const':
/Applications/Arduino.app/Contents/Java/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: error: ld returned 1 exit status
Error compiling for board Teensy 3.6.
I've stripped the code down as much as I could, and experimented with it, but to no success.
What puzzles me is that the vector defined within .ino file does want to 'resize' without troubles,
but the one defined in ABC.h makes trouble.
Could someone please explain what am I doing wrong. Thank you!
The code looks like this:
TEST_vector.ino
Code:
#include <vector>
#include "ABC.h"
using namespace std;
std::vector<double> myVector(10);
// myAbc contains a vector 'abcVector_'
ABC myAbc;
void setup() {
// vector defined within .ino file does resize ok:
myVector.resize(10);
// attempt to resize a vector defined in external .h file
// doesn't compile:
myAbc.resizeAbcVector(10);
}
void loop() {
}
ABC.cpp
Code:
#include "ABC.h"
ABC :: ABC( void ){
// empty for simplicity
}
void ABC :: resizeAbcVector ( unsigned long sizeRequest ){
unsigned long currentSize = abcVector_.size();
// this thing makes trouble:
if ( sizeRequest > currentSize )
abcVector_.resize( sizeRequest );
}
ABC.h
Code:
#ifndef ABC_H
#define ABC_H
#include <vector>
using namespace std;
class ABC {
public:
ABC( void );
~ABC(){};
void resizeAbcVector ( unsigned long sizeRequest );
std::vector<double> abcVector_;
};
#endif