[C++-sig] template function

Luca Sbardella luca.sbardella at gmail.com
Wed Aug 29 16:55:24 CEST 2007


Thanks Dave,
but I did put a concrete type in the template argument.
My previous email was a bit confusing.
Here is the function template used for exporting

template<class A, class B>
void export_test(string name)  {

typedef test<A,B> etest;

class_<etest>(name.c_str())

   .....  Implemented all the member functions

   .def("keys",       &etest::keys<boost::python::list>)
;

}

So there is a real concrete type in the template argument. However when I
try to compile I get a strange error message

In function 'void export_test(const std::string&)':
error: expected primary-expression before '>' token
error: expected primary-expression before ')' token

This message is quite strange, infact I get it even if I don't instantiate
the function template '' export_test''.

Luca

On 29/08/2007, David Abrahams <dave at boost-consulting.com> wrote:
>
>
> on Wed Aug 29 2007, "Luca Sbardella" <luca.sbardella-AT-gmail.com> wrote:
>
> > and used the export_test class to export to python. For example
> >
> > export_test<double,double>("test_real");
> >
> > Everything works fine if I comment
> > .def("keys",       &etest::keys<L>)
> > in the export_test. All the member functions of test are available in
> Python.
> >
> > However if I insert the .def("keys",       &etest::keys<L>)  the code
> will not
> > compile!!!
> >
> > Am I missing something?
>
> Yeah, &etest::keys<L> isn't valid C++ unless L is a type.  It isn't,
> in your case.  You can't take the address of a (member) function
> template; you can only take the address of a particular specialization
> (instance) of that template, so you need to substitute a real, concrete
> type name for L.
>
> HTH,
>
> --
> Dave Abrahams
> Boost Consulting
> http://www.boost-consulting.com
>
> The Astoria Seminar ==> http://www.astoriaseminar.com
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070829/a71ce3af/attachment.htm>


More information about the Cplusplus-sig mailing list