Visualizzazione dei risultati da 1 a 4 su 4

Discussione: [c++]reference

  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826

    [c++]reference

    ciao .
    Ho la seguente funzione:
    [code]
    HRESULT CManageSingleton::LoadShader(string strFilePathShader, ID3D10Device* pd3dDevice, ID3D10Effect& pEffect)
    {
    HRESULT hr;

    WCHAR str[MAX_PATH];
    V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"Phong.fx" ) );
    DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS;
    #if defined( DEBUG ) || defined( _DEBUG )

    dwShaderFlags |= D3D10_SHADER_DEBUG;
    #endif
    V_RETURN( D3DX10CreateEffectFromFile( str, NULL, NULL, "fx_4_0", dwShaderFlags, 0, pd3dDevice, NULL,
    NULL, &pEffect, NULL, NULL ) );

    }
    [code]

    la funzione
    V_RETURN( D3DX10CreateEffectFromFile( str, NULL, NULL, "fx_4_0", dwShaderFlags, 0, pd3dDevice, NULL,
    NULL, &pEffect, NULL, NULL ) );

    si aspetta un **pEffect ma io ho passato alla funzione(precedente) la variabile per reference!
    come faccio a fare arrivare un puntatore a puntatore alla funzione sopra?
    Scusa ma utilizzo i reference da poco.
    Ciao.

  2. #2
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381
    Alla LoadShader passi per refence un oggetto, presumo, non un puntatore.
    E' sufficente usare un puntatore temporaneo a quell'oggetto.
    Puoi fare:
    codice:
    ID3D10Effect* pTmp = &pEffect;
    ...
    
    V_RETURN( D3DX10CreateEffectFromFile( str, NULL, NULL, "fx_4_0", dwShaderFlags, 0, pd3dDevice, NULL,
    NULL, &pTmp, NULL, NULL ) )
    This code and information is provided "as is" without warranty of any kind, either expressed
    or implied, including but not limited to the implied warranties of merchantability and/or
    fitness for a particular purpose.

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826
    grazie shodan.
    E se volessi che ID3D10Effect* pTmp fosse uno shared pointer che a 0 riferimenti si distrugge come potrei fare?
    Ho incluso gli header di boost nelle relative cartelle di vs 2008.
    Solo che non conosco i "namespaces" e non riesco a navigare gli oggetti con l'intellisense.

  4. #4
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381
    Non devi distruggere pTmp. E' un puntatore ad un oggetto esistente il cui lifetime è esterno alla funzione. Inoltre è solo un puntatore fittizzio per poter invocare l'altra funzione nel modo corretto. Lo puoi lasciare così come l'ho scritto senza preoccuparti.

    Per quanto riguarda gli 0 riferimenti, lo shared_ptr se ne occupa in automatico. (E' fatto apposta). Quindi puoi copiarlo, passarlo per copia, restituirlo per valore e fa tutto lui.

    boost usa come namespace boost
    This code and information is provided "as is" without warranty of any kind, either expressed
    or implied, including but not limited to the implied warranties of merchantability and/or
    fitness for a particular purpose.

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.