Mail Archives: djgpp/1999/03/10/08:05:00
Endlisnis <s257m AT unb DOT ca> wrote:
> I get this error when I compile the code given.
>In function `int main(int, char **)':
>t.cc(26) Error: request for member `Data' in `b.List<int>::Current()()', which
>is of non-aggregate type `int'
>----
>template <class T>
>class Node
>{
> public:
> T Data;
> };
>
>template <class T>
>class List
>{
> Node<T>* Curr;
>
> public:
> T Current();
> };
>
>int main(int argc, char *argv[])
>{
> List<int> b;
> int c = b.Current().Data;
> /*Note this line. It is assigning an 'int' to an 'int', but the compiler
>gets an error. */
> return 0;
>}
>
>template <class T>
>T List<T>::Current()
>{
> return Curr->Data;
> }
In noted line you are really referencing `Node<int>::Data.Data' (see? `Data' is
referenced twice). But `Data' is int (in your example).
the right line should be
int c = b.Current();
or you should change definition of List<T>::Current not to return T but Node&
(or Node for const method version).
David
- Raw text -