10 years, 4 months ago.

Vectors in Mbed

Hi

I added the library <vector>

and now i can not call the erase function from vector lib?

how can i do it?

Is not mbed able to use c++ libs?

std::vector<Class_name *>vec;

// and now i want to erase an element

vec.erase(i);

// the compiler give me an error like:

//Error: No instance of overloaded function "std::vector<_TypeT, _Allocator>::erase [with _TypeT=Class_Name *, _Allocator=std::allocator<Class_Name *>]" matches the argument list in "Class_Name/Class_Name_Controller.cpp"


2 Answers

10 years, 4 months ago.

mbed is able to use standard C++ libs. I don't know however what 'i' is in your case. If it is just an integer that would explain the issue, it wants a pointer to the element to erase, not just an integer, so in that case it cannot find an erase function that matches your argument.

If you indeed used an integer, you should instead use:

vec.erase(vec.begin()+i);

That said you seem to have an LPC1768. Thats good compared to most others because it has alot of flash memory. Which is needed to include the vector lib, the vector lib is larger than the total flash memory on the LPC812. Now the LPC1768 has alot more, and you'll be fine with just the vector lib. But in general you want to avoid such things on a microcontroller, what is trivial for a PC is alot for a uC. For example also using cout is a bad idea, simply because of the memory it costs.

Accepted Answer
10 years, 4 months ago.

Thanks a lot, it worked

very well explained.

And you are right i have a LPC1768.