Re: is this typedef valid?

From: Ioannis Vranos (ivr_at_remove.this.grad.com)
Date: 02/17/05


Date: Thu, 17 Feb 2005 04:45:04 +0200

lou zion wrote:

> hi all,
>
> i want to create a vector where each element is an array of 40 doubles. is
> this valid? something like:
>
> void abc( std::vector<double> InVals)
> {
> typedef double DataSeriesType[40];
> std::vector<DataSeriesType> DataSeriesX;
>
> DataSeriesType NewData;
> DataSeriesX.push_back(NewData);
>
> for (int i=0; i<(int)InVals.size(); i++) {
> DataSeriesX[0][i]=InVals[i];
> }
> }
>
> the above is not good code, i know, i'm just using it as an example of
> syntax, not style.
>
> essentially i want to store an array (or possibly a vector) in a vector. if
> i just store a pointer to an array in a vector, what happens if i delete
> that element? do i need to deallocate storage somehow? i'd prefer an array,
> but if there's a better way to do this, please enlighten.

#include <vector>

void abc(const std::vector<double> &InVals)
{
     using namespace std;

     vector<vector<double> >DataSeriesX;

     vector<double> NewData(40);

     DataSeriesX.push_back(NewData);

     for(vector<double>::size_type i=0; i<InVals.size(); ++i)
        DataSeriesX[0][i]=InVals[i];
}

or

#include <vector>

void abc(const std::vector<double> &InVals)
{
     using namespace std;

     typedef vector<double>DataSeriesType;

     vector<DataSeriesType> DataSeriesX;

     DataSeriesType NewData(40);

     DataSeriesX.push_back(NewData);

     for(vector<double>::size_type i=0; i<InVals.size(); ++i)
        DataSeriesX[0][i]=InVals[i];
}

-- 
Ioannis Vranos
http://www23.brinkster.com/noicys


Relevant Pages

  • Re: Finding the nearest match without reusing results
    ... comparing an array with a value generates an array of Trues and ... Any diff with wrong State or with used Store is implicitly zeroed out. ... Each must be larger than the absolute value of the maximum Sales ... go.....it just needs to return the closest match. ...
    (microsoft.public.excel.programming)
  • Re: DataType for storing pointlist (x,y,z)?
    ... Using vb6, ado, writing to mdb format ... If I want to store an array of 3 doubles, what would be best for the data ...
    (microsoft.public.vb.database.ado)
  • Re: read keyboard input and storing in an array?
    ... > I'm trying to store user input in an array, ... You have the beginnings of that logic already since your prompt tells the ... 201st value since the array only has room for 200 values. ... This will force you to store the int values as Integer ('Integer' ...
    (comp.lang.java.help)
  • Re: Challenge: reading ascii data
    ... to store all the data before producing any output. ... would be bad practice in terms of memory consumption to use a standard ... So I use hashes to create a two-level "sparse array", ... Well the original problem definition was: ...
    (comp.lang.fortran)
  • Re: attempting an actual game...
    ... >>> and inflexible by the absurd decision to use a bit array for square ... as then one has 8 bits in which to store a color and a few flags ... Using a 2D int (or, ... > Change direction and you may eventually complete a game. ...
    (comp.games.development.programming.misc)