I have structure template with two objects and a template class. I want to be able to have this struct as one of the types that the class object can be and I want the class's functions to be able to manipulate them. At the same types, I want this class to manipulate standard CPP types like int and float.
template<typename T>
struct user_type
{
T obj1;
T obj2;
};
template<class T>
class array
{
int length;
T* ar_ptr;
public:
void setArray();
};
template<class T> void array<T>::setArray()
{
for(int i = 0; i < length; ++i)
{
(*(ar_ptr+ i)).obj1 = 0;
(*(ar_ptr+ i)).obj2 = 0;
}
}
template <typename T>
void array<T>::setArray()
{
for(int i = 0; i < length; ++i)
{
*(ar_ptr+ i) = 0;
}
}
I tried to give it two different declarations to the set function but I am getting the following error:
error: redefinition of 'setArray'
error: member reference base type 'float' is not a structure or union
What is the right way to declare this function and instantiate it? I want the same class to manipulate a struct and a start CPP type.