Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    [C++] Struct dentro una Struct

    Salve,

    volevo creare una struttura composta da variabili int e da un'altra struttura contenente TCHARs.

    Codice PHP:
    struct formPref
    {
        
    int top;            // Seek 0   (4 Bytes)
        
    int left;           // Seek 4   (4 Bytes)
        
    int indexDevice;    // Seek 8   (4 Bytes)
        
    int indexSamples;   // Seek 12  (4 Bytes)
        
    int indexBitrate;   // Seek 16  (4 Bytes)
        
    int indexMode;      // Seek 20  (4 Bytes)
        
    int indexEmphasis;  // Seek 24  (4 Bytes)
        
    int indexServer;    // Seek 28  (4 Bytes)

        
    struct formPrefString
        
    {
            
    TCHAR szName[128]; // Seek 32  (128 Bytes)
            
    TCHAR szGenre[64]; // Seek 160 (64 Bytes)
            
    TCHAR szWeb[128];  // Seek 224 (128 Bytes)
        
    };
    }; 
    avrei voluto riempire la struttura in questo modo ma non credo sia il modo giusto:

    codice:
    		// Fill Struct
    		//
    		formPref fp;
    		memset(&fp, 0, sizeof(fp));
    
    		fp.top           = 65535;
    		fp.left          = 0;
    		fp.indexDevice   = 15;
    		fp.indexSamples  = 40;
    		fp.indexBitrate  = 10;
    		fp.indexMode     = 60;
    		fp.indexEmphasis = 999999999;
    		fp.indexServer   = 16776960;
    
    		formPref::formPrefString fps = { _T("Name.."), _T("Genre"), _T("Web....") };
    Ma tuttavia non posso accedere ai campi tramite: fp.formPrefString ...

    come dovrei organizzare la struttura?

    NB, all'inizio avevo una struttura tipo:

    codice:
    struct formPref
    {
    	int top;            // Seek 0   (4 Bytes)
    	int left;           // Seek 4   (4 Bytes)
    	int indexDevice;    // Seek 8   (4 Bytes)
    	int indexSamples;   // Seek 12  (4 Bytes)
    	int indexBitrate;   // Seek 16  (4 Bytes)
    	int indexMode;      // Seek 20  (4 Bytes)
    	int indexEmphasis;  // Seek 24  (4 Bytes)
    	int indexServer;    // Seek 28  (4 Bytes)
    
    	TCHAR szName[128]; // Seek 32  (128 Bytes)
    	TCHAR szGenre[64]; // Seek 160 (64 Bytes)
    	TCHAR szWeb[128];  // Seek 224 (128 Bytes)
    };
    ma in questo caso non potevo usare = per assegnare stringhe ai membri TCHAR...
    Alla batteria dai retta ballA

  2. #2
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,466
    Intendi

    codice:
    struct formPref 
    { 
        int top;            
        int left;           
        int indexDevice;    
        int indexSamples;   
        int indexBitrate;   
        int indexMode;      
        int indexEmphasis;  
        int indexServer;    
    
        struct formPrefString 
        { 
            TCHAR szName[128]; 
            TCHAR szGenre[64]; 
            TCHAR szWeb[128];  
        } fps; 
    };
    
    ...
    
        formPref fp = { 65535, 0, 15, 40, 10, 60, 999999999, 16776960, 
                           { _T("Name.."), _T("Genre"), _T("Web....") }
                      };
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  3. #3
    perfetto, anche se mi sarebbe piaciuto fare una cosa del tipo:

    codice:
    	
    // Fill Struct
    //
    formPref fp;
    memset(&fp, 0, sizeof(fp));
    
    fp.top           = 65535;
    fp.left          = 0;
    fp.indexDevice   = 15;
    fp.indexSamples  = 40;
    fp.indexBitrate  = 10;
    fp.indexMode     = 60;
    fp.indexEmphasis = 999999999;
    fp.indexServer   = 16776960;
    
    fp.fps = { _T("Name.."), _T("Genre"), _T("Web....") };
    ovvero assegnare le int con = e le stringhe direttamente, ma naturalmente mi ada errore all'ultima riga
    Alla batteria dai retta ballA

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.