I have a header file, but I don't know how to do it: I am new to templates.

template <class T> 
class Array 
{
    public:
        Array(int l, int h);
        Array(int s);
        Array(const Array& other);
        ~Array();
        T& operator[](int index);
        const T& operator[](int index) const;
        int get_size() const 
        {return size;}
    private:
        int low;
        int  high;
        int size;
        int offset;
        T *ptr;  
};

Include the implementation of the class in the header file too. Without getting into excessive detail, template classes and member function definitions aren't split across multiple files.

I implemented this one in my main. And, i have to make declerations to each. How do I declare it? I wrote it like this:

template <class T>
T Array<T>::Array (int l, int h)
{
    if (l>h)
    {
        cout<<"Bad number!\n"<<endl;
        exit (1);
    }
    else
    {
        low = l;
        high = h;
        size=(-1*l)+h;
        for (int i=0; i<size; i++)
        {
            ptr[i]=false;
        }
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.