1

I have a quick question for you all. I'm trying to convert over some ActionScript code to C++ and am having a difficult time with this one line:

private var edges:Vector.<Array>

What is this exactly? Is this essentially a multidimensional vector then? Or is this simply declaring the vector as a container? I understand from researching that vectors, like C++ vectors, have to be declared with a type. However, in C++ I can't just put down Array, I have to use another vector (probably) so it looks like:

vector<vector<T> example;

or possibly even

vector<int[]> example;

I don't expect you guys to know the C++ equivalent because I'm primarily posting this with AS tags, but if you could confirm my understand of the AS half, that would be great. I did some googling but didn't find any cases where someone used Array as it's type.

3
  • What's the nature of this application you're trying to port from AS 3.0 to C++? Commented May 30, 2011 at 22:42
  • A* Pathfinding code. There is an array of nodes, and then there is another array that, I think, is filled with another array of numbers (an index), of which edges that node touches. This is what I'm porting over: active.tutsplus.com/tutorials/games/… Commented May 30, 2011 at 22:47
  • you can fill your vector with a vector (instead of an Array) : var vector : Vector.<Vector.<Number>>; Commented May 31, 2011 at 8:29

1 Answer 1

1

From Mike Chambers (adobe evangelist) :

"Essentially, the Vector class is a typed Array, and in addition to ensuring your collection is type safe, can also provide (sometimes significant) performance improvements over using an Array."

http://www.mikechambers.com/blog/2008/08/19/using-vectors-in-actionscript-3-and-flash-player-10/

Essentially the vector in C++ is based on the same principles. As far as porting a vector of Arrays in AS3 to C++, well that's not a conversion that is clear cut in principle, as you could have a collection (array) of various types in C++, such as a char array. However, it appears you've got the idea, as you've pretty much posted examples of both avenues in your question.

I would post some code but I think you've got it exactly. Weather you use a vector within a vector or you declare a specifically typed collection I think comes down to a matter of what works best for you specific project.

Also you might be interested in:

http://www.mikechambers.com/blog/2008/09/24/actioscript-3-vector-array-performance-comparison/

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! This was exactly the information I needed. Well done. =]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.