Thread View: comp.std.c++
2 messages
2 total messages
Started by Douglas C. Schmidt
Thu, 05 Oct 1995 23:02
Problems compiling template typedefs
Author: Douglas C. Schmidt
Date: Thu, 05 Oct 1995 23:02
Date: Thu, 05 Oct 1995 23:02
61 lines
1890 bytes
1890 bytes
Hi,
I get the following error:
----------------------------------------
% CC y.C
"y.C", line 17: Error: :: is not a class name as required for a qualifer.
"y.C", line 17: Error: ")" expected instead of "&".
2 Error(s) detected.
----------------------------------------
When I compile the following program with SunC++ 4.0.1 and GNU G++
2.7.0:
----------------------------------------
class ACE_INET_Addr {};
class ACE_SOCK_Acceptor
{
public:
typedef ACE_INET_Addr PEER_ADDR;
};
template <class PEER_ACCEPTOR>
class ACE_Acceptor
{
public:
int open (const PEER_ACCEPTOR::PEER_ADDR &addr);
};
template <class PEER_ACCEPTOR> int
ACE_Acceptor<PEER_ACCEPTOR>::open (const PEER_ACCEPTOR::PEER_ADDR &addr) { retu
rn 1; }
^^^^^^^
Error is here...
main ()
{
ACE_Acceptor<ACE_SOCK_Acceptor> acceptor;
ACE_INET_Addr addr;
acceptor.open (addr);
return 0;
}
----------------------------------------
Note that if I declare open() in the class definition then the SunC++
compiler doesn't complain.
I believe this should be acceptable C++ template syntax, right? Can
anyone tell me if there are compilers available that get this right?!
Thanks,
Doug
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Re: Problems compiling template typedefs
Author: Nathan Myers
Date: Sat, 07 Oct 1995 00:25
Date: Sat, 07 Oct 1995 00:25
35 lines
2111 bytes
2111 bytes
"Douglas C. Schmidt" <schmidt@cs.wustl.edu> wrote:
> I get the following error:
>"y.C", line 17: Error: :: is not a class name as required for a qualifer.
>... when I compile the following program with SunC++ 4.0.1 and GNU G++:
> struct ACE_SOCK_Acceptor { typedef ACE_INET_Addr PEER_ADDR; };
>
> template <class PEER_ACCEPTOR>
> struct ACE_Acceptor { int open (const PEER_ACCEPTOR::PEER_ADDR &addr); };
> Can anyone tell me if there are compilers available that get this right?!
Correct C++ syntax would be
int open(const typename PEER_ACCEPTOR::PEER_ADDR& addr);
Unfortunately, I don't know of any compilers that accept the "typename"
keyword yet. (It's a fairly recent addition.) The "typename" keyword
is necessary to inform the lexer that the name is a type, both to help
decouple the parser from the lexer, and to permit some declarations that
would otherwise be terminally ambiguous.
Until the compilers come up to date, you will need to muddle along, doing
experiments to figure out what kind of heuristic (if any) your compiler
uses to identify type names in such contexts.
Nathan Myers
myersn@roguewave.com
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads