Pages: [1]   Go Down
Author Topic: Using vectors with Arduino 1.0.2  (Read 462 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm new to Arduino, but fairly experienced with C++. I'm trying to use vectors in my project and I found multiple STLs online, but I'm having trouble integrating them into my project. Below is how I need to declare the vectors in the header file of my class.

     vector<int> x_location;
     vector<int> y_location;

I consistently get the following error, even after saving the STL files in the Arduino include folder and including them in my sketch and header file:

          error: ISO C++ forbids declaration of 'vector' with no type

Please help!
Logged

California
Offline Offline
Sr. Member
****
Karma: 2
Posts: 433
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://arduino.cc/forum/index.php/topic,45626.0.html
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 220
Posts: 6587
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Using dynamic memory allocation on a processor with only 2K or so of RAM and no virtual memory is a bad idea. See http://www.eschertech.com/articles/items/art100730.html for some reasons why. As most STL classes use dynamic memory allocation, this means you have to program without most of the STL.

You can simulate a vector using an array and a counter, you just need to decide in advance what is the maximum size you will ever let the vector grow to.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Ayer, Massachusetts, USA
Offline Offline
Edison Member
*
Karma: 50
Posts: 1765
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Also bear in mind that the compiler shipped the Arduino is rather old, so it may not have any support for features added in the last few years to the C++ language.
Logged

Pages: [1]   Go Up
Jump to: