I have a template class:
template<class T>
class A{
T a, b;
public:
A(A<T> const & o) : a(o.a), b(o.b){}
A(T const & _a, T const & _b) : a(_a), b(_b){}
};
A<double> d(1.2, 4.5);
A<float> f = d; //error: conversion from A<double> to non-scalar type A<float> requested
How do i define a conversion function for my class?
My compiler is g++ 4.7.0
You could make a template constructor:
Then you should be able to convert any class
A<U>to any classA<T>as long asUis convertible toT.