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

    [c++]specializzazione funzione template

    ciao.
    Ho una classe con una funzione template che vorrei
    specializzare a seconda che :
    1)eseguita da qualsiasi parametro template tranne CEmpty
    2)eseguita dal parametro template = a CEmpty


    codice:
    //questa è la classe , non è un template ma se serve renderla tale si puo fare, anche
    //se vorrei capire bene le possibilità e le differenze tra specializzazione di 
    //funzioni template e di classi template, sul diversi libri non l'ho capita bene , quindi sono
    //qui a chiedere
    class CVboCreator
    {
    public:
    	CVboCreator(void){};
    	~CVboCreator(void){};
    	
    	void GenAndBindVertexArray(GLuint& vertexArrayObject)
    	{
    		glGenVertexArrays(1, &vertexArrayObject);
    		glBindVertexArray(vertexArrayObject);
    	}
    
            //questa è la funzione, vorrei che eseguisse questo per tutti i parametri
            //template tranne CEmpty che non deve fare niente , ma essere solo richiamata
            //ed eseguita(esegue nessun codice ma esegue)
    	template<class Data>
    	bool Create(GLuint& vertexArrayObject, GLuint& vertexBufferObject, Data* VBOData)
    	{
    		glGenBuffers(1, &vertexBufferObject);
    		glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
    		glBufferData(GL_ARRAY_BUFFER, sizeof(*VBOData), glm::value_ptr(*VBOData), GL_STATIC_DRAW);
    		
    		return true;
    	}
    
    };
    so specializzare le classi template ma non le funzioni , chiedevo anche se è possibile specializzare per tutti i tipi tranne CEmpty in modo che tutte le chiamate alla funzione che non hanno CEmpty come parametro template eseguano un codice comune (quello di Create nell esempio).


    grazie.

  2. #2
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381
    Usa un semplice overload.
    codice:
    bool Create(GLuint& vertexArrayObject, GLuint& vertexBufferObject, CEmpty* VBOData) {
        ...
    }
    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 risolto

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 © 2025 vBulletin Solutions, Inc. All rights reserved.