Template question
From: Ali R. (nospam_at_nospam.com)
Date: 02/25/04
- Next message: Ali R.: "Re: Template question"
- Previous message: Leor Zolman: "Re: [C++] Linkage Error w/ Code Sample from Lippman..."
- Next in thread: Ali R.: "Re: Template question"
- Reply: Ali R.: "Re: Template question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 25 Feb 2004 22:16:15 GMT
I am trying to pass an instance of a template class to a function, but seem
to run into difficulties.
here is the class def
template <class TYPE = int,int Upper = 10, int Lower = 0>
class CArray
{
private:
typedef CArray <TYPE,Upper,Lower> ARRAYTYPE;
public:
CArray();
CArray(const TYPE &Data);
CArray(const ARRAYTYPE &Data);
virtual ~CArray();
const ARRAYTYPE &operator = (const ARRAYTYPE &Data);
const TYPE &operator [] (int Index) const;
TYPE &operator [] (int Index);
const TYPE &GetAt(int Index) const;
void SetAt(int Index,TYPE Data);
int Size() const;
int LowerBound() const;
int UpperBound() const;
private:
TYPE *m_Array;
void CopyArray(const ARRAYTYPE &Data);
};
and main
int main()
{
CArray<int,10,0> Array1;
CArray<double,20,1> Array2;
PrintArray(Array1);
PrintArray(Array2);
return 1;
}
now here is the question. what do i put as the function parameter for
PrintArray so that i can pass it any of those arrays in main
void PrintArray(......Array)
{
for (int i = Array.GetLower();i <= Array.GetUpper();i++)
{
cout << Array[i] << endl;
}
}
Thanks
Ali R.
- Next message: Ali R.: "Re: Template question"
- Previous message: Leor Zolman: "Re: [C++] Linkage Error w/ Code Sample from Lippman..."
- Next in thread: Ali R.: "Re: Template question"
- Reply: Ali R.: "Re: Template question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|