I need to turn this code for a class that checks for a out-of-bound value:

class array
    {public :
            int & operator [] (int);        // Prototype; overloaded operator
            int size ()                     // In-line function
                    {return ub - lb + 1;
                    };
            int lbound ()
                    {return lb;
                    };
            int ubound ()
                    {return ub;
                    };
            list = new int[10];             // Constructor
            list ();                        // Default constructor
            array (int)
    private :
            int *list               // Arrays of size 9;
            int lb;                 // Lower bound of array; set by user
            int ub;                 // Upper bound of array; set by user
    };

into a template. Im not sure how i would even start this. any help would be great

Edited 3 Years Ago by Reverend Jim: Fixed formatting

wrap your code in code tags.

also your class and functions should have a template header above it

template <class T>
class myClass
{
T myMember;
}

template <class T>
T myClass<T>::getSomething(){return myMember;}

something like that
You can use T as a class type if you don't know it beforehand.

Edited 5 Years Ago by jkoske: n/a

wrap your code in code tags.

<snip>

template <class T>
class myClass
{
T myMember;
}

template <class T>
T myClass<T>::getSomething(){return myMember;}

Oh, the irony.

Edited 5 Years Ago by Narue: n/a

This article has been dead for over six months. Start a new discussion instead.