Re: is this typedef valid?
From: Ioannis Vranos (ivr_at_remove.this.grad.com)
Date: 02/17/05
- Next message: Victor Bazarov: "Re: is this typedef valid?"
- Previous message: lou zion: "is this typedef valid?"
- In reply to: lou zion: "is this typedef valid?"
- Next in thread: E. Robert Tisdale: "Re: is this typedef valid?"
- Reply: E. Robert Tisdale: "Re: is this typedef valid?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Victor Bazarov: "Re: is this typedef valid?"
- Previous message: lou zion: "is this typedef valid?"
- In reply to: lou zion: "is this typedef valid?"
- Next in thread: E. Robert Tisdale: "Re: is this typedef valid?"
- Reply: E. Robert Tisdale: "Re: is this typedef valid?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|