Problem with Visual Studio 2008 and release configuration (struct and vector)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Fabullo
    New Member
    • Feb 2010
    • 1

    Problem with Visual Studio 2008 and release configuration (struct and vector)

    Hi everyboby,

    I have some problem using the release configuration of Visual Studio and the following code. Is there anybody who can tell me how to use struct with inside a vector?

    Thank you

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <assert.h>
    #include <time.h>
    #include <iostream>
    #include <fstream>
    #include <math.h>
    #include <string.h>
    #include <errno.h>
    #include <string>
    #include <sstream>
    #include <errno.h>
    #include <vector>
    #include <algorithm>
    #include <set>
    
    using namespace std;
    
    typedef struct{
    	int progressivo;
    	int colonna_temporale_IN[1500];
    	int colonna_temporale_OUT[1500];
    }risorsa_localita;
    
    typedef struct{
    	int progressivo;
    	vector <risorsa_localita > risorse_localita;
    }struttura_risorse_localita;
    
    struttura_risorse_localita *vettore_risorse_localita;
    
    int main() 
    { 
    	int i,j,k;
    
    	vettore_risorse_localita=(struttura_risorse_localita *)calloc(1000,sizeof(struttura_risorse_localita));
    
    	for(i=0;i<1000;i++){
    
    		vettore_risorse_localita[i].progressivo=i;
    
    		for(j=0;j<5;j++){
    
    				risorsa_localita risorsa_appoggio;
    
    				for(k=0;k<1500;k++){risorsa_appoggio.colonna_temporale_IN[k]=0;}
    				for(k=0;k<1500;k++){risorsa_appoggio.colonna_temporale_OUT[k]=0;}
    
    				vettore_risorse_localita[i].risorse_localita.push_back(risorsa_appoggio);	
    		}
    
    
    		cout << "PREMI INVIO\n";
    		cin.get();
    
    		return 1;
    	}
    }
    Last edited by Banfa; Feb 3 '10, 10:10 AM. Reason: Added code tags
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You haven't said what the problem is which makes it hard to help.

    However you absolutely should no use malloc/callo/free in C++ especially with classes as the constructors do not get called. Allocate your memory with new and release it with delete.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Also, keep in mind that a C++ class is implemented as a struct. So if you can use a vector with a class then you already know how to use it with a struct.

      A C++ struct is identical to a C++ class that has all members public.

      Comment

      Working...