jeudi 28 juillet 2016

trying to Initialize map variable of unknown parameter type at run time

does anyone understand why this piece of code:

struct array{ 
    
    template<typename Key, typename Value>
    array(const Key& ki, const Value& val) {             
        if( isset(ki) ){
            std::map<Key, Value> var = Innitialize<Key, Value>(ki, val); 

            var[ki] = val;                               //error: invalid array assignment

            std::cout << "testing...";
        }  
    }
    array(){} 
};

template<typename T, typename U>
std::map<T, U> Innitialize(const T& ki, const U& val){                               
     std::map<T, U> out; 
     return out;
};

is printing error: invalid array assignment ? I've tried several other means to try to see how i could initialize a map object whose' type parameters are not known until run time. available suggestions opine that i can only do this if on c++11 or later. any walk-around please ?

Aucun commentaire:

Enregistrer un commentaire