   The C++ equiv of C# (int)
  I know int functions the same in C++ and C#, but I noticed a difference when looking at this C# code versus this C++ code, for example I want to create a 1D array of int type, so consider this,int map[5 * 5] ={  ...};Now in C# you could do something like this,int mapWidth = map.GetLength(1);int mapHeight = map.GetLength(0);But obviously C++ doesn't offer such a function call in type int, so what would you do in C++ to achieve the same goal?   
Quote:But obviously C++ doesn't offer such a function call in type int, so what would you do in C++ to achieve the same goal?The second code snippet you posted is perfectly valid C# and C++, assuming "map" exists and has the appropriate method. I think you should rephrase your question.   ;  No the second wont compile in C++, it gives the must be a class/structure to the left of GetLength compile error. I am looking for the equivalent of the C# in C++.C# already offers that, but C++ doesn't so what is the equivalent of this, or a function that will serve the same purpose?   ;  In C++ an array is just a block of data its not an object. Nowhere in it does it store the size of the array.You can sometimes use the sizeof() operator on the array, but, this only works if the array is a static size and you aren't using sizeof() on a pointer to the array (or it'll tell you the size of the pointer). Don't rely on this!You can use things like the vector size in stl to get an array-like structure similar to the one in C#.But in general, in C++ you need to keep track of how many elements are in an array yourself.   ;  It seems what you're really asking about is the difference between C++ arrays and C# arrays, not C++'s int type and C#'s int type.Quote:C# already offers that, but C++ doesn't so what is the equivalent of this, or a function that will serve the same purpose?The answer to your question is that in C++, you would (typically) create an array class that stores (along with the array data itself) the dimensions of the array. (Examples of such a class would be std::vector for 1-d arrays, and boost::multi_array for N-d arrays.)   ;  So this step is basically not needed than as I already know the size and I could just declare that early on and instead of map[5 * 5], I see I am following this tutorial in C# it is a 10 part video tutorial but I like to port to learn things and better my skills, this is my first attempt at C# -> C++ I have done some AS3 -> C++, but seems to be easier to follow than some C# stuff. Thanks for your assistance.   ;Quote:No the second wont compile in C++, it gives the must be a class/structure to the left of GetLength compile error. I am looking for the equivalent of the C# in C++.The actual snippet is valid syntax, however. With the appropriate context (i.e., appropriate definition of a map object) it will compile. This is why I wanted you to clarify the question.Also, moving to FB.   ;Quote:Original post by jpetrieThe actual snippet is valid syntax, however. With the appropriate context (i.e., appropriate definition of a map object) it will compile. This is why I wanted you to clarify the question.He posted the definition of the map variable in the 1st snippet, as an array of ints.   ;Quote:Original post by XTAL256He posted the definition of the map variable in the 1st snippet, as an array of ints.True, but since we're talking about two different code samples in two different languages, I think it's reasonable to interpret them as coming from different contexts. (FWIW, when I read them, I did not immediately make the connection between the map variable referred to in the first example and the map variable referred to in the second.)   ;  C++://In this case you don't know the size of the array, so you'd use sizeofchar *foobar[] = { "foo", "bar", "123", "abc" };int foobar_size = sizeof(foobar) / sizeof(foobar[0]);//Here you decide what the size will be, so there's really no need to do it the way you did in C#. You'll also want to avoid using magic numbers.const int mapWidth = 5, mapHeight = 5;int map[mapWidth * mapHeight];jyk: I've never used C#, but I'll assume that the second code snippet only works on 2-dimensional arrays, whereas the first code snippet initializes a 1-dimensional array, so in a way you're right. :)   