Vectors in Arduino
Standard C++ for Arduino might be an option. It lets you use the STL vector in Arduino.
Arduino C++ vector of int
These are my shots that vector is not included or you are missing namespace std::
. The compiler explicitly points out that it does not know what vector is.
What is more, you don't initialize fields like this in C++. You have to do it in the constructor:
#include <vector>
#include <iostream>
#define MEMORY_SIZE 10
class Clazz {
std::vector<int> memory;
public:
Clazz() : memory(MEMORY_SIZE){}
int memory_size() {return memory.size();}
};
int main() {
Clazz c;
std::cout << c.memory_size() << std::endl;
return 0;
}
C++ Arduino Vector issues with mismatched types?
Arduino's Vector
library (https://github.com/janelia-arduino/Vector) accepts a statically allocated array at construction time, unlike std::vector
which you can pass a size_t
into.
template <typename T>
class Vector
{
public:
Vector();
template <size_t MAX_SIZE>
Vector(T (&values)[MAX_SIZE],
size_t size=0);
// ...
};
You will need to pass an array instead of a size_t
, or use a different data structure during these member initializers:
// ...
ClockTimeAtLastBounce(ballCount),
Height(ballCount),
BallSpeed(ballCount),
Dampening(ballCount),
Colours(ballCount)
std::vector ::push_back causes a link error on Arduino
Try this
template <typename T, typename U>
void addVectorToVector(std::vector<T>* oldVector, std::vector<U> &input)
{
for (int i = 0; i < input.size(); i++) {
T inputVar = (T) input[i];
oldVector->push_back(inputVar);
}
}
Related Topics
C++ Array Assignment of Multiple Values
Too Many Initializers for 'Int [0]' C++
Static Variables in an Inlined Function
Why Is It Undefined Behavior to Delete[] an Array of Derived Objects via a Base Pointer
How to Read-Write Into/From Text File with Comma Separated Values
How to Recover View Space Position Given View Space Depth Value and Ndc Xy
How to Leverage Qt to Make a Qobject Method Thread-Safe
Template Instantiation Details of Gcc and Ms Compilers
How to Parse Date/Time from String
Linking a Shared Library with Another Shared Lib in Linux
What Is "Pch.H" and Why Is It Needed to Be Included as the First Header File
Does the 'Offsetof' MACro from <Stddef.H> Invoke Undefined Behaviour
Preparation for Std::Iterator Being Deprecated
Evaluate a String with a Switch in C++
C++ Sort Keeping Track of Indices
Passing a Variable as a Template Argument
Why Doesn't Narrowing Conversion Used with Curly-Brace-Delimited Initializer Cause an Error