retourner un double tableau
	
	
		bonjour à tous, j'ai un petit soucis pour retourner un tableau à 2 dimensions, afin de l'utiliser dans une autre fonction. Voici mon mon code :
	Code:
	
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 
 | int ** init_spectre(int N, int P)
{	
 
	int * signal_discret = new int[N]; 
	delete [] signal_discret;
 
	int i,i2,j,k;
	for (i=0;i<N;i++)
	{
		i2=i;
		j=0;
 
		for(k=1;k<=P;k++)
		{
			j=j<<1;
			j=j|(i2&1);
			i2=i2>>1;
		}	
	cout << "i=" << i2 << " et j=" << j << endl;
 
 
	vector<vector<int> >spectre(N, vector<int>(2));  
 
	spectre[j][0] = 0;   
    spectre[j][1] = 0;   
 
    cout << "spectre[" << j << "][0]=" << spectre[j][0] << endl;   
    cout << "spectre[" << j << "][1]=" << spectre[j][1] << endl;   
 
	}
 
	return ** spectre;
} | 
 je ne vois pas ou est mon erreur...
merci pour votre aide
	 
	
	
	
		Re: retourner un double tableau
	
	
		
	Citation:
	
		
		
			
				Envoyé par miminou
				
			
			
	Code:
	
| 12
 3
 
 |  
	int * signal_discret = new int[N]; 
	delete [] signal_discret; | 
 
	 
 Heu ... ca sert à quoi ca ?
	 
	
	
	
		Re: retourner un double tableau
	
	
		
	Code:
	
int ** init_spectre(int N, int P)
 je ne pense pas que vector<vector<int> > correpond a int **.
utilise plustot un tableau. 
	Code:
	
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 
 |  
{	
 
	int * signal_discret = new int[N]; 
	delete [] signal_discret;
 
	int i,i2,j,k;
	for (i=0;i<N;i++)
	{
		i2=i;
		j=0;
 
		for(k=1;k<=P;k++)
		{
			j=j<<1;
			j=j|(i2&1);
			i2=i2>>1;
		}	
	cout << "i=" << i2 << " et j=" << j << endl;
 
 
	vector<vector<int> >spectre(N, vector<int>(2)); | 
 ton spectre sera detruit en sortie de ta fonction car il n'est pas dynamique.
vector<vector<int> >spectre(N, vector<int>(2)) est ici une variable local.
faut que tu utilise un new.
	Code:
	
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 
 |  
	spectre[j][0] = 0;   
    spectre[j][1] = 0;   
 
    cout << "spectre[" << j << "][0]=" << spectre[j][0] << endl;   
    cout << "spectre[" << j << "][1]=" << spectre[j][1] << endl;   
 
	}
 
	return ** spectre;
} |