Re: Question about arrays in objects
From: Jacques Labuschagne (jacques_at_clawshrimp.com)
Date: 01/17/04
- Next message: Erik Jälevik: "Re: Using vectors as arrays"
- Previous message: Leor Zolman: "Re: Question about arrays in objects"
- In reply to: Joec: "Question about arrays in objects"
- Next in thread: Joec: "Re: Question about arrays in objects"
- Reply: Joec: "Re: Question about arrays in objects"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 17 Jan 2004 15:48:38 +1300
Joec wrote:
> I want to create a 2d array as an object member.
>
> like:
>
> class x{
> private:
> const int num;
> int array[num];
> ...
>
> do I have to use a pointer like:
> int *px;
>
> then put the array in the constructor and use the pointer?
>
The obvious solutions are
class x{
int* array;
public:
explicit x(int N): array(new int[N]){}
~x(){ delete[] array; }
};
or
class x{
int array[12]; // yuck
};
or
template<int N>
class x{
int array[N];
};
HTH,
Jacques
- Next message: Erik Jälevik: "Re: Using vectors as arrays"
- Previous message: Leor Zolman: "Re: Question about arrays in objects"
- In reply to: Joec: "Question about arrays in objects"
- Next in thread: Joec: "Re: Question about arrays in objects"
- Reply: Joec: "Re: Question about arrays in objects"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|