Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* Help w/ templated sub-classes
@ 1997-08-04  4:00 magrasjc
  1997-08-14  4:00 ` Martin G. Jones
  0 siblings, 1 reply; 2+ messages in thread
From: magrasjc @ 1997-08-04  4:00 UTC (permalink / raw)



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) { } ?

-- 
 Unix Software Engineer looking for C++/UNIX/Motif/Perl/Tk/Flex
 Software Engineering position **NOW**. Currently in Austin at
 (512) 672-5778/magrasjc@texas.net. have Answering machine.



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Help w/ templated sub-classes
  1997-08-04  4:00 Help w/ templated sub-classes magrasjc
@ 1997-08-14  4:00 ` Martin G. Jones
  0 siblings, 0 replies; 2+ messages in thread
From: Martin G. Jones @ 1997-08-14  4:00 UTC (permalink / raw)



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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1997-08-14  4:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-08-04  4:00 Help w/ templated sub-classes magrasjc
1997-08-14  4:00 ` Martin G. Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox