[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: Non-G++ Programming Hints ...
From:       "Thomas Schilling" <snuffeler () gmx ! net>
Date:       2002-02-21 14:44:04
[Download RAW message or body]

In C++ an array's must size _must_ be a constant.
Even when you write "type* p = new type[size]"

You must use the Standart Template Library (STL).
vector<...> is it's dynamic array. So please use the
construct Erik showed you below - it's portable.

> > I wonder if
> >
> > f(short unsigned int n) {
> >   float array[n];
> >
> >   //  ...
> >
> > }
> >
> >
> > is allowed in C++ but not supported by all compilers or if it is not
> > allowed in C++ and just a g++ feature.
> 
> The latter. It's a g++ feature.
> 
> > If it is not allowed in C++ I would write
> >
> > f(short unsigned int n) {
> >   float * array = new float[n];
> 
> No, write
> 
> f(short unsigned int n) {
>   std::vector<float> array(n);
> 
>   // ...
> }
> 
> You can use QValueVector also.


 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic