Error 'new' cannot appear in a constant-expression

Hi,

I tried to create a double vector of object, similar to matrix but i need to put in the row a type of object and in the column another type of object.
I used this code:

static const int dim = 3;
packet **pack = new packet[dim];

but the compiler gives me these errors:

- `new' cannot appear in a constant-expression

- ISO C++ forbids initialization of member `pack'

- making `pack' static

- invalid in-class initialization of static data member of non-integral type `packet**'


this is the definition of packet header
#ifndef _PACKET_H
#define _PACKET_H


class packet
{
public:


packet();
~packet();
int in, out;
double tempo;
double get_time();
int get_in();
int get_out();

void inizializza();


};
#endif

and this is the definiton of CPP

/***************************************************************************
PACKET.C
***************************************************************************/
#include "packet.h"
#include "rand.h"
#include "global.h"
#include <time.h>
#include "stdlib.h"
#include <stdio.h>
#include <iostream>
using namespace std;
extern double inter;

packet::packet()
{

}

void packet::inizializza() {
int N = 9;
in = rand() % N;
out = rand() % N;
GEN_EXP(SEED, inter, tempo);

}

double packet::get_time() { return tempo; }
int packet::get_in() { return in; }
int packet::get_out() { return out; }

I don't understand if the error depends of the definition of pack or the definition of other part of my code.

If there are other topic that help me, link me please because i didn't find before.
If you need other info, tell me :)
or the definition of other part of my code.

That.
Topic archived. No new replies allowed.