Can anyone explain why i cannot push_back to a static vector of pointers in the constructor.
I can call attach which is a static method after the constructor runs and that works. But running it in the constructor does nothing.
Incidentally the code works when i tried it in VS.
Is this something related to dynamic memory?
I recently did something similar that what you are trying, but upon looking at my code, I put it in a begin() function I ran in setup(). I cannot remember why, but perhaps you are trying to add to the array (edit: vector) before it is available to do so.
On the other hand, I was doing some hardware setup in that member function as well, and perhaps it just landed there!
EDIT: this is where I had it:
//declared similarly, you see
std::vector<Brazos*> Brazos::instanceAddress;
//implemented in setup:
void Brazos::begin(int servo, int input)
{
instanceAddress.push_back(this);
The order of the constructor execution does not necessarily follow the order you have in your code. If the constructor depends on objects created in another constructor, that other constructor may not have run in the expected order.