Templates -> Typ des Templates?



  • Hallo Forum.
    Angenommen, es liegt folgender Code vor.

    template<class T>
    class CT
    {
    public:
    		CT() { ; } ;
    		void vAdd( const T & t ) { m_I.push_back(t); } ;
    private:
    		std::vector<T> m_I;
    };
    
    class CA
    {
    public:
    	CA() { ; } ;
    
    	template<class T>
    	void vAdd_Value( const T & t )
    	{
    		// je nachdem was t für ein Typ ist:
    		m_ints.vAdd( t ) ;
    		// oder:
    		m_doubles.vAdd( t ) ;
    	};
    
    private:
    	CT<int> m_ints;
    	CT<double> m_doubles;
    };
    

    Wie kann ich denn in CA::vAdd_Value herausfinden, welche Funktion ich herausfinden muss? [bin Anfänger bzgl. Templates].

    Vielen Dank,
    Lisa



  • nix template, hier nur überladung.

    class CA 
    { 
    public: 
        CA() { ; } ; 
    
        void vAdd_Value( int t ) 
        { 
            m_ints.vAdd( t ) ; 
        }; 
        void vAdd_Value( double t ) 
        { 
            m_doubles.vAdd( t ) ; 
        }; 
    
    private: 
        CT<int> m_ints; 
        CT<double> m_doubles; 
    };
    

Anmelden zum Antworten