Is there any other way to assign values to template class members in constructors, other than using explicit initialization for fundamental types or casting?
template <class T>
struct A
{
public:
T member;
A() :member(T()) // or :member(static_cast<T>(1.0f))
{}
};
I want to assign a value of 1.0 to member in the constructor. Can I do this without casting?
Yes, use an integer, which can be implicitly converted to any numeric type: