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

Recommended Answers

All 3 Replies

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.

Ok i'll remember that for next time, thank you for the tip

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.

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.