C++ template casting

c++templates

I'm a little lost in how to cast templates. I have a function foo which takes a parameter of type ParamVector<double>*. I would like to pass in a ParamVector<float>*, and I can't figure out how to overload the casting operator for my ParamVector class, and Google isn't helping me that much. Does anyone have an example of how to do this? Thanks.

EDIT: Adding some code, sorry I'm an idiot and didn't phrase the original question well at all;

template<class T> class ParamVector 
{
public:
    vector <T> gnome;
    vector <T> data_params;
}

template<class T> class ParamVectorConsumer
{
 public:
 ParamVector<T> test;
}

ParamVector<float> tester;
ParamVectorConsumer<double> cons;
cons.ParamVector = tester

will fail to compile. I would like to know how to write it so that I can cast the float version of tester to a ParamVector double. Thanks

EDIT2: Casting was the wrong word. I don't mind writing extra code, I just need to know how to get this to be accepted by the compiler so that I can write some sort of conversion code.

Best Solution

I'm not sure but maybe you need some like this:

template< typename TypeT >
struct ParamVector
{
    template < typename NewTypeT >
    operator ParamVector< NewTypeT >()
    {
        ParamVector< NewTypeT > result;
        // do some converion things
        return result;
    }

    template< typename NewTypeT >
    ParamVector( const ParamVector< NewTypeT > &rhs )
    {
        // convert
    }

    template < typename NewTypeT >
    ParamVector& operator=( const ParamVector< NewTypeT > &rhs )
    {
        // do some conversion thigns
        return *this;
    }


};
ParamVector< double > d1;
ParamVector< float > f1;
f1 = d1;

You can choose use conversion operator or operator= - I've provided both in my example.

Related Question