-2

I have experience in Java, but not in C++ and unfortunately I have to write small application in C++ for Tizen. The problem is I have to store data as follows:

  • data should be stored in one object
  • ideal object would be java ArrayList (or LinkedList) of ArrayList of Points

How can I achieve that in C++? Could you propose any sample declaration, definition and get(), add() examples? Is the following a good way to do that:

std::vector<std::vector<Tizen::Graphics::Point> > __strokes;
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
Marek
  • 3,935
  • 10
  • 46
  • 70
  • 1
    What is the data that you need to store, and how do you need to access the stored data? Without those details, any answer you'll get will be far too vague to be useful. – Pete Becker Jun 26 '13 at 01:09
  • I want to store Points. I write something on canvas end on each onTouchMove I want to store new Point in my variable. When I start to draw new stroke, I want to move into new position in ArrayList and create new List of Points and so on... – Marek Jun 26 '13 at 01:18
  • 1
    Both `ArrayList` and `LinkedList` [have native counterparts](https://developer.tizen.org/help/topic/org.tizen.native.appprogramming/html/guide/base/arraylist_linkedlist.htm) in Tizen. – Michael Jun 26 '13 at 06:15
  • I have found it. But still having problems with declaration of ArrayList inside of ArrayList. How can I do that? – Marek Jun 26 '13 at 06:37
  • Just a tip! If you compile with C++11 support, you don't need the extra space between '> >'. If you're using gcc or clang, this can be done by adding -std=c++11 in the commandline – Shump Jun 26 '13 at 09:11

1 Answers1

3

Use the std::vector class from the standard library

std::vector is a sequence container that encapsulates dynamic size arrays.The elements are stored contiguously, which means that elements can be accessed not only through iterators, but also using offsets on regular pointers to elements. This means that a pointer to an element of a vector may be passed to any function that expects a pointer to an element of an array.

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
  • I can't add element to my vector: __strokes[0][0] = currentPosition; The application crashes. When I debug it I can see in "variables" Window following information: Target request failed: There is no member or method named std::_Vector_base >, std::allocator > > >::_Tp_alloc_type. – Marek Jun 26 '13 at 01:47
  • @Marek: When you create `__strokes` (bad name, BTW -- don't use double underscores) it's empty. You need to start with something like `__strokes.push_back(std::vector());`, then you can use something like `__strokes[0].push_back(mouse_position);` to add a point to that stroke. – Jerry Coffin Jun 26 '13 at 02:27
  • I was trying that before but it didn't worked, and now it worked.. :) Why is it a bad name? It is used in an official example for Tizen... – Marek Jun 26 '13 at 02:38