Re: Define pointer to member as a template
On Apr 16, 12:38 pm, Michael DOUBEZ <michael.dou...@free.fr> wrote:
ds a =E9crit :
template<class Tp>
std::map<std::string, Tp::ptr> themap<Tp>::smap;
though the typedef compiles, the specialization of the map fails.
You have to indicate that Tp::ptr is a type.
template<class Tp>
std::map<std::string, typename Tp::ptr> themap<Tp>::smap;
Michael
Hi Michael,
thanks for the reply. You would be correct if I did not actually
define the type! The problem is that
typedef int Tp::*ptr; defines a pointer to integer members of class
Tp. This line compiles fine as well. However, the next line (std::map
memberr) results in
'std::map' : 'Tp::ptr' is not a valid template type argument for
parameter '_Ty' on MSVC.
If I use the typename in the declaration and instantiation of the map
and then typedef the pointer in my classes, like in the following:
template<class Tp> class themap
{
public:
static std::map<std::string, typename Tp::ptr> smap;
};
template<class Tp>
std::map<std::string,typename Tp::ptr> themap<Tp>::smap;
class test : public themap<test>
{
public:
int a;
int b;
typedef int test::*ptr;
};
I get 'ptr' : is not a member of 'test'... plus that the point is to
have the typedef in the template.
Thanks a lot!