From: mgjones@vegauk.co.uk (Martin G. Jones)
Subject: Re: Help w/ templated sub-classes
Date: 1997/08/14 [thread overview]
Message-ID: <33f34ce4.35755749@news.demon.co.uk> (raw)
In-Reply-To: 33E69610.1B1F@texas.net
On Mon, 04 Aug 1997 21:55:12 -0500, magrasjc@texas.net wrote:
>Greetings everyone,
>
>I am trying to get the following code to compile on a g++ 2.7.2.2
>and libg++ 2.7.2 on DEC UNIX 3.2... but I cant discern what the
>external function defintion's header should look like...
>
>Thanks in advance for your help,
>
>J.C. Magras
>
>#include <function> // yields unary_function template
>
>***** given this generic template
>template<class Protocol,class Result>
>class jack:pubic unary_function<Protocol, Result>
>{
>public:
>Result& jack<Protocol&>::operator(Protocol&){};
>};
>
>***** given this template specialization
>template<class pTCPIP,class pTCPIP>
>class jack<pTCPIP,pTCPIP>:public unary_function<Protocol,Result>
>{
>friend class pTCPIP;
>public:
> Result& jack<Protocol>::operator()( Protocol &) ;
>};
>************
>what is the function signature/header for:
>pTCPIP& jack :: operator() (pTCPIP & e) { } ?
I haven't got a copy of g++ to try this on but it compiles with the
DEC CXX compiler.
Your main problem is that the syntax of your specialised class is
incorrect. I have highlighted the differences with comments.
// functional required on dec compiler.
#include <functional> // yields unary_function template
// I presume you meant public and not pubic :-)
template<class Protocol,class Result>
class jack : public unary_function<Protocol, Result> {
public:
// presumably operator() - a set of parentheses were missing
// in the original code
Result& jack<Protocol&>::operator()(Protocol&) {};
};
class pTCPIP;
// note syntax for specialising template class
// i.e. no template<...> construct
class jack<pTCPIP, pTCPIP> {
friend class pTCPIP;
public:
// no need to explicitly scope the operator. If you did, use:
// jack<pTCPIP, pTCPIP>:: ... not jack<Protocol>::
// specify the concrete type, not Result for ret val.
pTCPIP& operator()(pTCPIP&);
};
// Define the function out of line:
pTCPIP& jack<pTCPIP, pTCPIP>::operator()(pTCPIP& p) {
return p; // do whatever
}
Martin.
************
Martin G. Jones, Software Engineer
mgjones@vegauk.co.uk
prev parent reply other threads:[~1997-08-14 4:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-08-04 4:00 Help w/ templated sub-classes magrasjc
1997-08-14 4:00 ` Martin G. Jones [this message]
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox