delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/03/10/08:05:00

From: david DOT stegbauer AT cz DOT opel DOT com
X-Lotus-FromDomain: GMCZECHIA AT EDSHUBEUROPE
Sender: david DOT stegbauer AT cz DOT opel DOT com
To: s257m AT unb DOT ca
cc: djgpp AT delorie DOT com
Message-ID: <41256730.00478CB3.00@derumg01.cyberlink.eds.com>
Date: Wed, 10 Mar 1999 14:05:34 +0100
Subject: Re: GCC thinks there is an error when I don't.
Mime-Version: 1.0
Reply-To: djgpp AT delorie DOT com


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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019