[C++-sig] how to pass function pointer to a constructor of a template class when wrap it by pyste
Qinfeng(Javen) Shi
shiqinfeng at gmail.com
Thu Sep 14 09:31:01 CEST 2006
Dear all,
I have a class (in hello.cc file) whose constructor assgins a value to a
global function pointer. It is compiled by gcc and it works well. But it
always reports an error when I used bjam to build the hello.cpp file (which
is produced by pyste). If I remove the template, it works. But I do need the
template. Does anybody know how to wrap it correctly?
Any suggestion is appreciated.
The hello.cc, hello.pyste, Jamfile are as following:
/********************hello.cc*************/
#include <stdio.h>
float add(float a, float b)
{
return a+b;
}
float minus(float a, float b)
{
return a-b;
}
float (*op)(float a, float b) = add;
template<class P>
class cover_tree {
P value;
public:
cover_tree(float (* metric)(float a, float b))
{
op= metric;
}
cover_tree()
{
}
};
int main()
{
float a,b,c;
a = 1;
b = 2;
cover_tree<float> ct2(minus);
c = op(a,b);
printf("%f\n",c);
}
/************************hello.pyste*********/
cover_tree = Template('cover_tree','hello.cc')
cover = cover_tree("float")
Function("main", "hello.cc")
/************************Jamfile***********/
# This is the top of our own project tree
project-root ;
# Include definitions needed for Python modules
import python ;
extension hello # Declare a Python extension called hello
: hello.cpp
# requirements and dependencies for Boost.Python extensions
<template>@boost/libs/python/build/extension
;
--
Javen
Research School of Information Sciences and Engineering
Australian National University
Locked Bag 8001
Canberra ACT 2601
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060914/7ea24d9a/attachment.htm>
More information about the Cplusplus-sig
mailing list