AppData\Local\Temp\ccsbCXFP.ltrans0.ltrans.o: In function `global constructors keyed to 65535_0_ArrayList.cpp.o.2153':
<artificial>:(.text.startup+0x46): undefined reference to `ArrayList<int>::ArrayList(int)'
<artificial>:(.text.startup+0x50): undefined reference to `ArrayList<int>::ArrayList(int)'
<artificial>:(.text.startup+0x60): undefined reference to `Device<float>::Device(ArrayList<int>)'
collect2.exe: error: ld returned 1 exit status
exit status 1
Compilation error: exit status 1
ArrayList.h
template<typename E>
class ArrayList {
private:
int _size;
E *const _array = {};
void grow(int minCapacity);
void ensureExplicitCapacity(int minCapacity);
void ensureCapacityInternal(int minCapacity);
public:
ArrayList();
ArrayList(int initialCapacity);
ArrayList(E *const initialArray);
your class definition is missing the trailing }; and the .cpp would need to #include "ArrayList.h"
you also have to think it terms of who owns the array and add a destructor. May be something like this
.h
#ifndef __ARRAYLIST___
#define __ARRAYLIST___
#include <Arduino.h>
template<typename E>
class ArrayList {
private:
int _size;
E* _array; // Removed const here as you want to change it
void grow(size_t minCapacity);
void ensureExplicitCapacity(size_t minCapacity);
void ensureCapacityInternal(size_t minCapacity);
public:
ArrayList(size_t initialCapacity = 10);
ArrayList(E* const initialArray);
~ArrayList(); // Add a destructor to release allocated memory
};
#endif
.cpp
#include "ArrayList.h"
template<typename E>
ArrayList<E>::ArrayList(size_t initialCapacity) : _size(0), _array(new E[initialCapacity]) {}
template<typename E>
ArrayList<E>::ArrayList(E* const initialArray) : _size(0), _array(initialArray) {}
template<typename E>
void ArrayList<E>::grow(size_t minCapacity) {
// Implement the grow function
}
template<typename E>
void ArrayList<E>::ensureExplicitCapacity(size_t minCapacity) {
// Implement the ensureExplicitCapacity function
}
template<typename E>
void ArrayList<E>::ensureCapacityInternal(size_t minCapacity) {
// Implement the ensureCapacityInternal function
}
template<typename E>
ArrayList<E>::~ArrayList() {
delete[] _array; // Release the allocated memory in the destructor
}
you'll have to explore exactly what it is you want from the constructor using an array
see also The rule of three/five/zero ➜ make the right decisions there, might need
/var/folders/x7/p119gjkx60n54k0hjx6p26br0000gn/T//ccPsrUEV.ltrans0.ltrans.o: In function `global constructors keyed to 65535_0_ArrayList.cpp.o.1815':
<artificial>:(.text.startup+0x60): undefined reference to `Device<float>::Device(int*)'