 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Momchil Velikov Guest
|
Posted: Sun Sep 21, 2003 10:12 am Post subject: Cannot invoke a templated ctor |
|
|
The following program produces error at the definition of ``b''. However it
compiles fine the second (supposedly equivalent) form of the templated
constructor. Why the two alternatives aren't equivalent ?
template<class Obj>
struct ptr_to_member
{
typedef void (Obj::* type) ();
};
struct A
{
A (void (*fn) ())
{
}
#if 1
template<class Obj>
A (typename ptr_to_member <Obj>::type fn)
{
}
#else
template<class Obj>
A (void (Obj::* fn) ())
{
}
#endif
};
void foo ()
{
}
struct bar
{
void baz ()
{
}
};
A a (foo);
A b (&bar::baz);
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Graeme Prentice Guest
|
Posted: Wed Sep 24, 2003 10:27 pm Post subject: Re: Cannot invoke a templated ctor |
|
|
On 21 Sep 2003 06:12:58 -0400, [email]velco (AT) fadata (DOT) bg[/email] (Momchil Velikov) wrote:
| Quote: | The following program produces error at the definition of ``b''. However it
compiles fine the second (supposedly equivalent) form of the templated
constructor. Why the two alternatives aren't equivalent ?
|
Because ptr_to_member <Obj> is a non-deduced context - a nested name
specifier is a non deduced context - 14.8.2.4 para 4. The compiler
won't deduce Obj to be bar because the standard doesn't allow it to.
It was discussed here recently
http://makeashorterlink.com/?I2B622EF5
Graeme
| Quote: |
template<class Obj
struct ptr_to_member
{
typedef void (Obj::* type) ();
};
struct A
{
A (void (*fn) ())
{
}
#if 1
template
A (typename ptr_to_member
{
}
#else
template
A (void (Obj::* fn) ())
{
}
#endif
};
void foo ()
{
}
struct bar
{
void baz ()
{
}
};
A a (foo);
A b (&bar::baz);
|
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|