[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
ISO C++ forbids initialization in array new
From: |
Florian . Hudelist |
Subject: |
ISO C++ forbids initialization in array new |
Date: |
Tue, 13 May 2008 10:12:12 -0700 (PDT) |
User-agent: |
G2/1.0 |
Hi,
the system in my uni has finally been upgraded and now I am having
some problems to compile my code.
I want to initialize an array of an object but this is not allowed
anymore. I found some discussions about this issue but no solution how
to rewrite it. Simplest case when this problem happens:
**************************************************************
class array
{
private:
public:
int s;
array(int i) {s = i;}
};
int main()
{
array *test;
test=new array[5](123);
}
***************************************************************
Compiling this code gives following error message:
$ g++ test.cpp
test.cpp: In function âint main()â:
test.cpp:22: error: ISO C++ forbids initialization in array new
How do I have to write the code to get the same result? I don't want
to add an extra function to initialise my objects.
Thanks,
Florian
- ISO C++ forbids initialization in array new,
Florian . Hudelist <=