[C/C++]cannot convert parameter 2 from 'char (*)[15]' to 'char *[]'

0

Witam,
przedstawie problem:

kod:

#define MAX_LINE_LENGTH 15
.. 
char (*av_tab)[MAX_LINE_LENGTH];
av_tab = new char[w][MAX_LINE_LENGTH];

..
//tu sobie uzupełniam av_tab
..

function(n, av_tab);

wywala mi error: w linii:
function(n, av_tab);

treści:
*cannot convert parameter 2 from 'char (*)[15]' to 'char []'

dodam, iż prototyp funkcji wygląda tak:

 function(int ac, char *av[]);

Próbowałem już chyba wszystkiego..
Dziękuję za podpowiedzi.

1

A próbowałeś napisać to poprawnie?
Ciekawi mnie skąd wziąłeś to:

new char[w][MAX_LINE_LENGTH];

Powinno być tak:

char** av_tab;
av_tab = new char*[w];
for(int i=0;i<w;i++)
  av_tab[i]=new char[MAX_LINE_LENGTH];
//
 function(int ac, char** av);
0

Oczywiście próbowałem już i tak jak mówisz, ale Visual wykrywa wyciek pamięci:

Detected memory leaks!
Dumping objects ->
{243} normal block at 0x0058F430, 10 bytes long.
 Data: <text_string1 > 62 65 61 6E 73 2E 6D 34 62 00 
{241} normal block at 0x0058E3A0, 15 bytes long.
 Data: <text_string1      > 62 65 61 6E 73 2E 6D 34 62 00 CD CD CD CD CD 
{240} normal block at 0x0058E350, 15 bytes long.
 Data: <text_string1             > 2D 6F 00 CD CD CD CD CD CD CD CD CD CD CD CD 
{239} normal block at 0x0058E300, 15 bytes long.
 Data: <beans.wav      > 62 65 61 6E 73 2E 77 61 76 00 CD CD CD CD CD 
{238} normal block at 0x0058E2B0, 15 bytes long.
 Data: <text_string1             > 38 30 00 CD CD CD CD CD CD CD CD CD CD CD CD 
{237} normal block at 0x0058E260, 15 bytes long.
 Data: <text_string1             > 2D 71 00 CD CD CD CD CD CD CD CD CD CD CD CD 
{236} normal block at 0x0058E210, 15 bytes long.
 Data: <text_string1       > 66 61 61 63 2E 65 78 65 00 CD CD CD CD CD CD 
Object dump complete.
 

Data: <text_string1> itp - są to ciągi którymi wcześniej wypełniam av_tab

Program nie przerywa działania przy wywołaniu funkcji,
ale ten raport o Detected memory leaks! mi nie daje spać..

0

Pewnie nie zwalniasz tej pamięci.

0

Zwalniam pamięć, po wywołaniufunction(n, av_tab); mam delete [] av_tab;

0

Zmodyfikowałem kod i wygląda tak:

char token0[] = "string0";
char token1[] = "string1";
char token2[] = "string2";
char token3[] = "string3";
char token4[] = "string4";
char token5[] = "string5";
	
int w = 6;

char** av_tab;
av_tab = new char*[w];
for(int i=0;i<w;i++)av_tab[i]=new char[MAX_LINE_LENGTH];

 for(int i=0;i<w;i++)
 {
   if(i == 0)strcpy(av_tab[i], token0);
   else if(i == 1)strcpy(av_tab[i], token1);
   else if(i == 2)strcpy(av_tab[i], token2);
   else if(i == 3)strcpy(av_tab[i], token3);
   else if(i == 4)strcpy(av_tab[i], token4);
   else if(i == 5)strcpy(av_tab[i], token5);
 }



function(w, av_tab);

for(int i=0;i<w;i++)delete av_tab[i];
delete [] av_tab;

i teraz wywala mi ?! :

Detected memory leaks!
Dumping objects ->
{243} normal block at 0x0054F430, 10 bytes long.
 Data: <string5 > 62 65 61 6E 73 2E 6D 34 62 00 
Object dump complete.

1 użytkowników online, w tym zalogowanych: 0, gości: 1