Re: Member function pointer template argument
From: Rolf Magnus (ramagnus_at_t-online.de)
Date: 03/20/04
- Next message: hua ye: "test"
- Previous message: Michael Koehmstedt: "Member function pointer template argument"
- In reply to: Michael Koehmstedt: "Member function pointer template argument"
- Next in thread: Michael Koehmstedt: "Re: Member function pointer template argument"
- Reply: Michael Koehmstedt: "Re: Member function pointer template argument"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 20 Mar 2004 11:13:03 +0100
Michael Koehmstedt wrote:
> Hi,
> I have a class as such:
>
> template< typename T, T > class Foo;
>
> template< typename R, typename C, typename P1, R (C::*mfp)(P1) >
> class Foo< R (C::*)(P1), mfp >
> {
> };
What do you need the last template parameter for? Write:
template< typename R, typename C, typename P1)
class Foo
{
//...
private:
R (C::* thepointer)(P1);
};
> My problem lies in the instantiation of the class. What I'd like to do
> is something like this, but it will not compile because func is a
> local variable:
>
> template< typename T >
> void makeFoo( T func )
> {
> Foo< T, func > foo;
> }
Right, func is a variable, but Foo expects a type as second template
parameter. Btw: please always include the error messages in your
postings.
> class Bar
> {
> void target( )
> {
> makeFoo( target );
> }
> };
>
> Basically, I want to be able to construct a Foo object without having
> to explicitly state the type of my member function.
Do it as I wrote above and add a constructor to Foo that takes the
function pointer. Then you should be able to just write:
class Bar
{
void target( )
{
Foo foo(&target);
}
};
- Next message: hua ye: "test"
- Previous message: Michael Koehmstedt: "Member function pointer template argument"
- In reply to: Michael Koehmstedt: "Member function pointer template argument"
- Next in thread: Michael Koehmstedt: "Re: Member function pointer template argument"
- Reply: Michael Koehmstedt: "Re: Member function pointer template argument"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|