so I am having some issues with creating and using pointers for vectors. The problem I'm trying to solve with these pointers, is referencing data, without having an excess amount of code. This is how I'm currently defining the variables:
// Data vectors
std::vector<int16_t> amountData;
std::vector<float> speedData;
std::vector<int16_t> *pointerr = &amountData; // Should be auto, just testing
I reference the data used multiple times through the code, which is why it would be easier if I could just have a pointer for the active data (data which I intend to use). I can't get it to work though, with using commands such as "*pointerr.size();" and such. I get the error:
request for member 'size' in 'pointerr', which is of pointer type 'std::vector<short int>*' (maybe you meant to use '->' ?)
and when using '*pointerr->size();', I get:
invalid type argument of unary '*' (have 'std::vector<short int>::size_type {aka long long unsigned int}')
I know its probably just me not fully understanding pointers/vectors, and that I'm probably missing something. Most of the other simallar questions don't really answer my problem (as far as I understand). I appreciate any sort of help/ideas and such, thanks in advance:)
std::vectordeclarations with different types? You won't be able to have one pointer refer to one of those sometimes and the other at other times. The type of the pointer must statically match the vector type.pointerrrefers to at runtime, then a reference instead of a pointer would be much easier to handle:auto& pointerr = amountData;and now you can usepointerrexactly as you wouldamountData(with very minor changes e.g. indecltype(pointerr)).