Juan Castiblanco
Juan Castiblanco

Reputation: 51

Pointing to an array created using std::array

I am trying to make a pointer to an array of doubles declared with array.h, but I can't get it to work. If I use the built-in double array it works fine, but I want to know if there is a way to point to the address of an array declared this way.

#include <iostream>
#include <array>

int main()
{
    using std::array;

    array <double, 3> dashTimes; 

    double *pr;

   pr = dashTimes;

   return 0;
}

edit: I sloppily wrote this while at work from a bigger problem. Sorry for any obvious mistakes.

Upvotes: 1

Views: 60

Answers (1)

juanchopanza
juanchopanza

Reputation: 227468

You probably want a pointer to the data held by the array. You can get a pointer to the first element thus:

double* pr = dashTimes.data();

or

double* pr = &dashTimes[0];

If you really want a pointer to the array, then

array <double, 3>* pr = dashTimes;

but that seems unlikely as it isn't very useful.

Upvotes: 3

Related Questions