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

    overloading in classi template

    Ciao a tutti!
    Chi mi sa dire come si fa a gestire gli overloading di operatori in una classe template in c++??
    Se la imposto normalmente come si fa in una classe mi da errore di sintassi...

  2. #2
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,288

    Moderazione

    Il linguaggio va indicato anche nel titolo, come da Regolamento.
    Qui l'ho inserito io.
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

  3. #3
    Utente di HTML.it L'avatar di XWolverineX
    Registrato dal
    Aug 2005
    residenza
    Prague
    Messaggi
    2,565
    Mostraci codice ed errore
    "Se proprio devono piratare, almeno piratino il nostro." (Bill Gates)

    "Non è possibile che 2 istituzioni statali mi mettano esami nello stesso giorno." (XWolverineX)

    http://xvincentx.netsons.org/programBlog

  4. #4
    Eccoti un esempio:
    Codice PHP:
    //
    // 3 november 2007
    // Compiled and tested with:
    // i686-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5367)
    //

    #include <iostream>

    namespace ig{
        
    template <typename T>
        class 
    GTest{
            private:
            const 
    T fField;
            
            public:
            
    void Dump (void) const;
            
            public:
            
    GTest (const T theField);
            
    GTest (const GTest <T> &theTest);
            
    GTest<Toperator + (const GTest <T> &theTest) const;
        };
    }

    namespace 
    ig{    
        
    template <typename T>
        
    GTest<T>::GTest (const GTest <T> &theTest):
        
    fField (theTest.fField){
        }
        
        
    template <typename T>
        
    GTest<T>::GTest (const T theField):
        
    fField (theField){
        }
        
        
    template <typename T>
        
    GTest<TGTest <T>::operator + (const GTest <T> &theTest) const{
            return 
    GTest <T> (fField theTest.fField);
        }
        
        
    template <typename T>
        
    void GTest<T>:: Dump (void) const{
            
    std::cout << "fField: " << fField << ";" << std::endl;
        }    
    }

    int main (int argcchar * const argv[]){
        
    typedef ig::GTest <intTestInt;
        const 
    TestInt aTest1 (1);
        const 
    TestInt aTest2 (2);
        const 
    TestInt aTestSigma aTest1 aTest2;
        
    aTestSigma.Dump (); // it prints out: fField: 3;
        
    return 0;


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.