Multi Forum Altomesima - programma che si blocca
Multi Forum Altomesima
Multi Forum Altomesima
Home | Profilo | Discussioni attive | Utenti | Cerca | FAQ
Nome Utente:
Password:
Salva Password
Dimenticato la tua Password?

 Tutti i forum
 Linguaggi di programmazione
 Linguaggio C
 programma che si blocca
 Nuova Discussione  Rispondi
 Versione Stampabile
Autore Discussione Precedente Discussione Discussione Successiva  

frea
Junior Member

22 Messaggi

Inviato il il 05/05/2004 :  17:20:36  Guarda il profilo di  Rispondi Citando
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;
}

mimc
Forum Admin

Italy
458 Messaggi

Inviato il 10/05/2004 :  10:31:33  Guarda il profilo di  Visita il Sito di mimc  Rispondi Citando
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,

Torna all'inizio della Pagina

mimc
Forum Admin

Italy
458 Messaggi

Inviato il 11/05/2004 :  10:55:26  Guarda il profilo di  Visita il Sito di mimc  Rispondi Citando
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

Torna all'inizio della Pagina
  Discussione Precedente Discussione Discussione Successiva  
 Nuova Discussione  Rispondi
 Versione Stampabile
Vai a:
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