What`s the problem about the c++ template???

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I want to use c++ template to complete a two dimension array.
and its storage sequence in memory is according to the row number.(don`t
like the common sequence)
the code is as follows:
////////////////////////////////////////////
#include <iostream.h>

template <class T> class ArrayTemp
{
friend class Array<T>; //what`s wrong here???
//when I declare all the members in the class as public,
//it become right.
//why???
T* tpBody;
int nRows,nCols,nCurrRow;
ArrayTemp(int nRsz,int nCsz)
{
tpBody = new T[nRsz * nCsz];
nRows = nRsz;
nCols = nCsz;
nCurrRow = -1;
}
public:
T& operator [] (int j)
{
return tpBody[nCurrRow + j*nRows];
}
};

template <class T> class Array
{
ArrayTemp<T> tTemp;
public:
ArrayTemp<T>& operator[] (int i)
{
tTemp.nCurrRow = i;
return tTemp;
}
Array(int nRsz, int nCsz):tTemp(nRsz,nCsz)
{}
};
void main(void)
{
Array<int> Array1(10,10);
Array1[0][0] = 100;
Array1[0][1] = 200;
cout<<Array1[0][0]<<endl;
cout<<Array1[0][1]<<endl;
}

--
collay


--
collay
.



Relevant Pages

  • Simple script annimation problem usig swing
    ... To change this template, ... public void destroy{ ... public state cstate; ... public static int respawn = 20; ...
    (comp.lang.java.programmer)
  • Re: Simple script annimation problem usig swing
    ... To change this template, ... public void destroy{ ... public state cstate; ... public static int respawn = 20; ...
    (comp.lang.java.programmer)
  • implementation details
    ... template class ) ... Retrieve then I'd like to implement some sort of overrun check. ... BUFFER(); ... unsigned int retrieve_count; ...
    (comp.lang.cpp)
  • Re: Replacing merge fields in headers/footers
    ... database, and a newly populated document can be requested at any time. ... to my way of thinking is to have a merge template ... I'm using exactly the same code to populate the fields in the ... >> private FileStream PopulateTemplateDocument(int theFileID, ...
    (microsoft.public.word.vba.general)
  • friend ostream& operator<< (ostream&, Array<T>&);
    ... Array(int itsSize = DefaultSize); ... int GetSize() const ... make sure the function template has already been declared and add after ... // implement the Constructor ...
    (alt.comp.lang.learn.c-cpp)