-2

I've seen this question before but wasn't answered super clearly. Completely new to c++, and don't understand how to initialize an array of pointers. If I was an array named submatrix of length 100 and to store pointers an array of doubles how would I do this? I've seen what I have below but don't know if I need to call new, or how to name it.

 submatrices = new *array[100] 
trosy
  • 93
  • 3
  • 7
  • 2
    Reading a good C++ book is always a good start – SwiftMango Mar 08 '15 at 21:17
  • Possible duplicate: http://stackoverflow.com/questions/4924212/c-what-does-this-double-pointer-array-structure-really-mean-i-have-trouble – Thomas Matthews Mar 08 '15 at 21:18
  • Please clarify your question: what is a submatrix? Is it a matrix that is a part of another matrix, like block matrices in mathematics? Also, you mention "I want it to be empty at first"; please clarify this too. BTW you can click "edit" to edit your question. – anatolyg Mar 08 '15 at 21:37
  • If you are new to C++ you shoudn't be using an array of pointers. For the most part, arrays and pointers are legacy features present for backwards compatibility, and for use by library developers to implement high-level features. – M.M Mar 08 '15 at 21:52

1 Answers1

2

It is not entirely clear to me what you're actually asking, but here is my interpretation:

double* a = new double[10];
double* b = new double[10];
...
double* j = new double[10];

double* submatrices[10] = {a, b, c, d, e, f, g, h, i, j};

If this is not what you want, please clarify your question.

fredoverflow
  • 256,549
  • 94
  • 388
  • 662
  • I just want to know how to instantiate submatrices, and I want it to be empty at first. Yes though it will be holding types double* like you have show. Do I not need the new for submatrices? – trosy Mar 08 '15 at 21:18
  • Your recurring use of the word "submatrix" seems to imply that you already have a matrix somewhere in your code. It would be really helpful if you could show the definition of that matrix in your question. – fredoverflow Mar 08 '15 at 21:20
  • "Empty" is not a property of an array commonly used in C++. It assumes an array to have a variable length, and while there are ways to mimick that, you may want to read up on basic C++ first. – Jongware Mar 08 '15 at 22:14