Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826

    [c++ stl]containers e puntatori

    ciao,
    allora ho un array del tipo:

    SimpleVertexText* Vvectors = new SimpleVertexText[m_pSubMeshData->CountFaceIndexes()];

    e un vector del tipo vector<SimpleVertexText*> pieno.

    vorrei passare gli elementi dal vector all' array con lo stesso ordine.

    Prima ero inceppato in un errore , perchè utilizzavo una mappa che mi ordinava gli elementi da sola , puo ' essere? era la map<> dell'stl ,ho letto da qualche parte che ordina i suoi valori.

    Per quanto riguarda il vector posso avere lo stesso problema?
    come si fa di preciso?

    grazie.

  2. #2
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381
    La map utilizza un albero binario per memorizzare i dati, da qui ordinamento.
    Per copiare un vector a un array basta usare std::copy(), a patto che l'array sia grande almeno quanto il vector.

    codice:
    std::copy(vec.begin(),vec.end(),Vvectors);
    Curiosità, perché devi copiare un vector in un array?
    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.
    devo copiare un vector in un array per creare un vertex buffer in dx 10, e la funzione per fare questo vuole come parametro appunto un array .
    Utilizzo il vector per fare operazioni di spostamento/clonazione vertici , normali ,binormali e tangenti.
    mi è piu' comodo in pratica che fare tutto con degli array.


    solo mi da quest'errore:



    c:\programmazione\d3dxcreatemeshfvf\emptyproject10 \materialphongtexture.cpp(146) : warning C4996: 'std::copy': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
    1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xutility(2576) : see declaration of 'std::copy'
    1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\xutility(2472) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'SimpleVertexText *' (or there is no acceptable conversion)
    1> c:\programmazione\d3dxcreatemeshfvf\emptyproject10 \materialphongtexture.h(13): could be 'SimpleVertexText &SimpleVertexText:perator =(const SimpleVertexText &)'
    1> while trying to match the argument list '(SimpleVertexText, SimpleVertexText *)'
    1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xutility(2485) : see reference to function template instantiation '_OutIt std::_Copy_opt<_InIt,SimpleVertexText*,std::forwar d_iterator_tag>(_InIt,_InIt,_OutIt,_InOutItCat,std ::_Nonscalar_ptr_iterator_tag,std::_Range_checked_ iterator_tag)' being compiled
    1> with
    1> [
    1> _OutIt=SimpleVertexText *,
    1> _InIt=std::_Vector_iterator<SimpleVertexText *,std::allocator<SimpleVertexText *>>,
    1> _InOutItCat=std::forward_iterator_tag
    1> ]
    1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xutility(2579) : see reference to function template instantiation '_OutIt std::_Copy_opt<std::_Vector_iterator<_Ty,_Alloc>,_ OutIt>(_InIt,_InIt,_OutIt,std::random_access_itera tor_tag,std::_Nonscalar_ptr_iterator_tag,std::_Ran ge_checked_iterator_tag)' being compiled
    1> with
    1> [
    1> _OutIt=SimpleVertexText *,
    1> _Ty=SimpleVertexText *,
    1> _Alloc=std::allocator<SimpleVertexText *>,
    1> _InIt=std::_Vector_iterator<SimpleVertexText *,std::allocator<SimpleVertexText *>>
    1> ]
    1> c:\programmazione\d3dxcreatemeshfvf\emptyproject10 \materialphongtexture.cpp(146) : see reference to function template instantiation 'SimpleVertexText *std::copy<std::_Vector_iterator<_Ty,_Alloc>,Simpl eVertexText*>(_InIt,_InIt,_OutIt)' being compiled
    1> with
    1> [
    1> _Ty=SimpleVertexText *,
    1> _Alloc=std::allocator<SimpleVertexText *>,
    1> _InIt=std::_Vector_iterator<SimpleVertexText *,std::allocator<SimpleVertexText *>>,
    1> _OutIt=SimpleVertexText *
    1> ]
    ciao.




    questo è parte del codice:
    codice:
    .
    .
    .
    .
    
    	SimpleVertexText* Vvectors= new SimpleVertexText[m_pSubMeshData->CountFaceIndexes()];
    	//SimpleVertexText* vectors = new  SimpleVertexText[m_pSubMeshData->CountFaceIndexes()];
    	SimpleVertexText* V = NULL;
    	for ( int i= 0 ; i <m_pSubMeshData->CountFaceIndexes();i++) {
    	
    		V = new SimpleVertexText();
    		i_indexes* idx = m_pSubMeshData->GetFaceIndexes(i);
    		tagPositionXYZ* pos = m_pSubMeshData->GetPositionXYZ(idx->nVertex);
    		
    		V->Pos.x = (*pos).x;
    		V->Pos.y = (*pos).y;
    		V->Pos.z = (*pos).z;
    
    		NORMAL* pnorm = m_pSubMeshData->GetNormal(idx->nNormal);
    		V->Normal.x = (*pnorm).nx;
    		V->Normal.y = (*pnorm).ny;
    		V->Normal.z = (*pnorm).nz;
    			
    		vect.push_back(V);
    	}
    	copy(vect.begin(), vect.end(), Vvectors);
    
    	return Vvectors;
    }

  4. #4
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381
    Se è solo quello il motivo, puoi fare anche:
    codice:
    funzione_che_accetta_un_array(&vec[0],vec.size());
    risparmiando un passaggio.
    Occhio: funziona solo per vector (o string), non altri container.
    Vedi http://www.parashift.com/c++-faq-lit....html#faq-34.3 per chiarimenti.

    Per l'altro problema. Ti serve un array di SimpleVertexText*, mentre stai allocando un array di SimpleVertexText.
    Devi fare:
    codice:
    SimpleVertexText** Vvectors= new SimpleVertexText*[m_pSubMeshData->CountFaceIndexes()];
    per avere un array di puntatori.
    Dopo puoi fare la copy.
    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.