www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/22/23:14:36

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: compile error: char *frame_ptr = new char[20][20] ('X')
Date: Sat, 22 Feb 1997 22:25:09 -0800
Organization: Two pounds of chaos and a pinch of salt
Lines: 38
Message-ID: <330FE2C5.2F2@cs.com>
References: <3316832f DOT 19841747 AT news DOT erols DOT com>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp103.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hades wrote:
> 
> #include <iostream.h>
> 
> main()
> {
>         char *frame_ptr = new char[20][20] ('X');
> 
>         delete[][] frame_ptr;
> }
> 
> ERROR message:
> 
>         initialization to 'char *'  from 'char (*) [20]'
> 
> 1) how did that happen?

A two dimensional array must be referenced with double indirection,
i.e.:

  char **frame_ptr = new char[20][20] ('X');

> 2) and when i free up the memory do i use:
> 
>         a) delete frame_ptr;
>         b) delete frame_ptr[];
>         c) delete frame_ptr[][];

I'm not an expert with C++, but I am pretty sure that a) will work.  b)
and c) might work as well - the best way to find out is to test it.

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I  |        fighteer AT cs DOT com         |
|    *  Proud user of DJGPP!  *    |   http://www.cs.com/fighteer   |
|    ObJoke:  If Bill Gates were a robber, not only would he        |
|     shoot you, but he'd send you a bill for the bullets.          |
---------------------------------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019