Multi Forum Altomesima
Multi Forum Altomesima
Multi Forum Altomesima
Home | Profilo | Discussioni attive | Utenti | Cerca | FAQ
 Tutti i Forum
 Linguaggi di programmazione
 Linguaggio C
 programma che si blocca

Nota: Devi essere registrato per poter rispondere.

Dimensioni video:
Nome Utente:
Password:
Messaggio:

* HTML abilitato
* Codice Forum disabilitato
Faccine
Felice [:)] Davvero Felice [:D] Caldo [8D] Imbarazzato [:I]
Goloso [:P] Diavoletto [):] Occhiolino [;)] Clown [:o)]
Occhio Nero [B)] Palla Otto [8] Infelice [:(] Compiaciuto [8)]
Scioccato [:0] Arrabbiato [:(!] Morto [xx(] Assonnato [|)]
Bacio [:X] Approvazione [^] Disapprovazione [V] Domanda [?]

 
   

C O N T R O L L A    D I S C U S S I O N E
frea Inviato - 05/05/2004 : 17:20:36
Scusate...
qualcuno sa perchč tale semplicissimo programmino si blocca a i=4???

#include "iostream"
#include "vector"
using namespace std;

class Numeri {
private:
int *Num;
public:
Numeri (int);
~Numeri ();
};

Numeri::Numeri (int num) {
Num = new int[num];
}

Numeri::~Numeri () {
delete [] Num;
}

int main () {

vector vett;
Numeri num(1);
for (register int i=0; i<10; i++) {
vett.push_back(num);
//vett.push_back(Numeri(1)); si blocca anche cosė!
cout <}

return 0;
}
2   U L T I M E    R I S P O S T E    (in alto le pių recenti)
mimc Inviato - 11/05/2004 : 10:55:26
Ricevo ed invio:

La tua classe č sprovvista di un adeguato copy-constructor. Quello
sintetizzato implicitamente dal compilatore (che provvede soltanto a
copiare il valore del membro Num) č inutilizzabile e produce
inevitabilmente un comportamento indefinito.

Max

mimc Inviato - 10/05/2004 : 10:31:33
OT ma interessante il link:

Hi Mimmo,
you can find more information about c++ on: www.cplusplus.com
Cheers

Nino

Pointers and arrays
The concept of array is very much bound to the one of pointer. In fact, the
identifier of an array is equivalent to the address of its first element, like
a pointer is equivalent to the address of the first element that it points to,
so in fact they are the same thing. For example, supposing these two
declarations:

int numbers [20];
int * p;

the following allocation would be valid:
p = numbers;
At this point p and numbers are equivalent and they have the same properties,
the only difference is that we could assign another value to the pointer p
whereas numbers will always point to the first of the 20 integer numbers of
type int with which it was defined. So, unlike p, that is an ordinary variable
pointer, numbers is a constant pointer (indeed an array name is a constant
pointer). Therefore, although the previous expression was valid, the following
allocation is not:
numbers = p;

because numbers is an array (constant pointer), and no values can be assigned
to constant identifiers.
Due to the character of variables all the expressions that include pointers in
the following example are perfectly valid:



// more pointers
#include "iostream.h"

int main ()
{
int numbers[5];
int * p;
p = numbers; *p = 10;
p++; *p = 20;
p = &numbers[2]; *p = 30;
p = numbers + 3; *p = 40;
p = numbers; *(p+4) = 50;
for (int n=0; n<5; n++)
cout << numbers[n] << ", ";
return 0;
}

10, 20, 30, 40, 50,


Vai all'inizio della pagina Multi Forum Altomesima - © 2002 -2008 Altomesima Online
Questa pagina e' stata aperta in 0,03 secondi. Superdeejay.net | Snitz Forums 2000