Linked Questions
230 questions linked to/from How do I declare a 2d array in C++ using new?
1
vote
3
answers
16k
views
Create 2D array with "new"? [duplicate]
I want to create a 2D array like the following.
char **dog = new char[480][640];
But it errors:
error C2440: 'initializing' : cannot convert from 'char (*)[640]' to 'char ** '
Types pointed ...
-2
votes
1
answer
18k
views
c++ dynamic array of pointers [duplicate]
I'm trying to understand how to create a dynamic array of pointers in C++.
I understand that new returns a pointer to the allocated block of memory and int*[10] is an array of pointers to int. But ...
-3
votes
1
answer
2k
views
How to properly work with dynamically-allocated multi-dimensional arrays in C++ [duplicate]
How do I define a dynamic multi-dimensional array in C++? For example, two-dimensional array? I tried using a pointer to pointer, but somehow it is failing.
1
vote
6
answers
8k
views
Can't declare dynamic 2D array in C++ [duplicate]
I've stuck on a problem - I can't declare 2D arrays in C++ using integers, written by user.
This code works fine-
cin>>m>>n;
int *array;
array=new int[m*n];
But I can't make this work -
...
1
vote
2
answers
4k
views
C++ fill 2D array [duplicate]
I am Java programmer. I'm trying to fill array in Win32 project
int **Data::matrixInitialize()
{
int** MX = new int*[n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; ...
-2
votes
2
answers
2k
views
How to heap allocate a 2D array in C++? [duplicate]
I am trying to do something like this:
std::string* Plane = new std::string[15][60];
However this code seems not to compile.
Is there any other way to accomplish the same result?
Thanks for any ...
0
votes
2
answers
1k
views
new matrix[N][N] failure [duplicate]
I'm having a stack overflow allocating a huge matrix on the stack (and I agree with that: it's stupid to allocate it there) and I'm writing the following code since I want to access the matrix's ...
0
votes
2
answers
609
views
Uninitialized memory warning on structs instantiated with new [duplicate]
So I have a Node struct
struct Node
{
int x = 0;
};
I make 20 Node*s. My understanding is that Node** is a pointer to the start of an array that holds pointers to Nodes.
constexpr int mazeSize = ...
-2
votes
1
answer
971
views
How do I declare a 2D array in C++ using new [Reopened]? [duplicate]
I have already seen :
How do I declare a 2d array in C++ using new?
But none of the answer seems to answer the question "How to declare a ** 2D array using new ** ?"
All the answers seems to show ...
2
votes
1
answer
1k
views
Store pointer to 2d array [duplicate]
So I have a private member in the class Map:
char **_map;
I then try to initialize the pointer array to a two dimensional char array like this:
std::vector<std::string> contents = StringUtils:...
1
vote
0
answers
2k
views
C++ Arrays in Visual Studio [duplicate]
I have just started to code in c++ and usually I used Emacs on a Linux. I then tried to continue work at home on a Windows using visual studio 2017.
This beginning of a code worked on the Linux but ...
0
votes
0
answers
1k
views
Creating a 2d array in a struct [duplicate]
I want to create a Matrix struct but I'm having a hard time initializing the 2d array
1:
struct Matrix{
int r, c;
Matrix(int r, int c){
this->r=r;
this->c=c;
for(int x=0;x<r;x++)...
1
vote
2
answers
1k
views
Is there a way to make a 2 dimensional array with the size from user inputs? [duplicate]
I'm working on a project that allows a user to row reduce matrices of any size, the size determined by user input. I've done this with a vector of vectors, but I can't figure out how to do it with ...
0
votes
1
answer
920
views
Fixed-size array of objects and sub-objects on the heap [duplicate]
I've searched and searched but haven't found anything that really clears up my confusion.
I'm representing a grid, and have two classes, e.g.:
class Term {
...
};
class GridPoint{
Term a;
...
0
votes
1
answer
428
views
Multidimensional Arrays on the Heap with Initializers [duplicate]
int ** foo()
{
int ** multiArray = new int*[3];
int one[3] = { 1, 2, 3 };
int two[3] = { 4, 5, 6 };
int three[3] = { 7, 8, 9 };
multiArray[0] = one;
multiArray[1] = two;
...