Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

User Defined Array Size

Posted on 1997-11-15
3
Medium Priority
?
971 Views
Last Modified: 2012-06-27
int * aPointer;
aPointer = new int[10][10];

Why won't it let me assign a multi-dimensional array?
0
Comment
Question by:BabyFace
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Accepted Solution

by:
wpinto earned 150 total points
ID: 1173282
Hi BabyFace,

When new is used to allocate a single object, it yields a pointer to that object; the resultant type is new-type-name * or type-name *. When new is used to allocate a singly dimensioned array of objects, it yields a pointer to the first element of the array, and the resultant type is new-type-name * or type-name *. When new is used to allocate a multidimensional array of objects, it yields a pointer to the first element of the array, and the resultant type preserves the size of all but the leftmost array dimension. For example:

new int[10][10]
yields type int (*)[10].

Therefore, the following code will not work because it attempts to assign a pointer to an array of int with the dimensions [10] to a pointer to type int:

int *aPointer;
aPointer = new int[10][10];

The correct expression is:

int (*aPointer)[10];
aPointer = new int[10][10];

Hope this helps

Wilfred
0
 
LVL 84

Expert Comment

by:ozo
ID: 1173283
line 3: error(3611): a value of type "int (*)[10]" cannot be
          assigned to an entity of type "int *"
  aPointer = new int[10][10];
           ^
//try
int (*aPointer)[10];
0
 
LVL 1

Author Comment

by:BabyFace
ID: 1173284
Good job.

Thanks.

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question