472,789 Members | 1,351 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,789 software developers and data experts.

Pointer-to-member as template argument

Hi all!

I'm writing a luabind/boost::python-like binding utility for a Squirrel
language to generating wrapper-functions for C++ classes and have a
problem with passing the pointer-to-member argument and deducing the
type of them.

I want to make a library which I can use like that:

class_<fs::path, sq_filesystem::ttag>(v, "path", no_base)
.constructor<const char*>()
.def("native_file_string", &fs::path::native_file_string)

I didn't have problems with contructor - I've just write a specialized
constructor for each type:

// base template
template<typename Class, int TypeTag, typename Sig>
struct sq_constructor {};

// const char* constructor template
template<class Class, int TypeTag>
struct sq_constructor<Class, TypeTag, const char*>
static int implementation(HSQUIRRELVM v)
if (sq_gettype(v, 2) == OT_STRING)
const char * sz;
sq_getstring(v, 2, &sz);
Class * o = new Class(sz);
sq_setinstanceup(v, 1, o);
return 0;
return sq_throwerror(v, "invalid param - string expected");

and implement a _class::method:

template<class Class, unsigned int TypeTag>
class class_
// adding a constructor
template<class Sig>
inline class_& constructor()
sq_constructor<Class, TypeTag, Sig>::implementation



But with creating method wrapper I have a problem. When I wrote:

template<typename Class, int TypeTag, typename Sig, Sig Method>
struct sq_method {};

template<class Class, int TypeTag, std::string (Class::*Method)() const>
struct sq_method<Class, TypeTag, std::string (Class::*)() const, Method>

static int implementation(HSQUIRRELVM v)
Class * o;

// sq_pushstring(v, o->*Method().c_str(), -1);
return 1;

template<class Class, unsigned int TypeTag>
class class_

// adding a method
template<class Sig>
inline class_& def(const SQChar * name, Sig func)
sq_register(name, sq_method<Class, TypeTag, Sig, func>::implementation);


I had error in class_::def() on template resolution:

`func' is not a valid template argument
error: it must be a pointer-to-member of
the form `&X::Y'

and "`<type error>' is not a class type"

What I'm doing wrong?
Adam Dziendziel, Poland
Jul 23 '05 #1
1 4432
Thing that I have noticed:

typedef std::string (fs::path::*ftype)(void) const;

// works
f = &sq_method<fs::path, 3334, ftype,

// doesn't work
ftype p = &fs::path::native_file_string;
f = &sq_method<fs::path, 3334, ftype, p>::implementation;

GCC 3.3.1 produces:
error: `p' is not a valid template argument
error: it must be a pointer-to-member of the form `&X::Y'

But I must pass the pointer through the .def() method of class_ which
fills the first three template parameters and hide this ugly syntax.
How can I do it?
Adam -Nalfein- Dziendziel, Poland

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Rasti | last post by:
Hello, I am trying to translate a C++ script to Java. Are there any differences between the C++ this-pointer and the Java this-pointer? Thank you
by: __PPS__ | last post by:
Hello everybody in a quiz I had a question about dangling pointer: "What a dangling pointer is and the danger of using it" My answer was: "dangling pointer is a pointer that points to some...
by: Riaan Cilliť | last post by:
Hi I'm trying to learn C, but I am struggling with using scanf and a struct. I want to define a structure and declare a variable of that type in int main. This has to be passed to a function and...
by: joe | last post by:
Hi all! I just have quick, possibly stupid question.... is it possible to do the following: int func(){ int *pointer; foo(pointer); } int foo(int *pointer){
by: Bill Potter | last post by:
I am a learning programmer in C and i want to know why some one would use pointers instead of going direct!
by: Dawn Minnis | last post by:
Hi When I compile my files I get the following: driver.c: In function `main': driver.c:49: warning: assignment makes integer from pointer without a cast driver.c:50: warning: assignment...
by: code break | last post by:
Hi all, What is the difference between stack pointer and frame pointer ? Any suggestions are welcome ,,,
by: reji_thomas | last post by:
Hi, I have a doubt in the following code: struct xyz { int x; long l; float f; };
by: william | last post by:
code segment: long int * size; char entry; ............. size=&entry; ************************************* Gcc reported 'assignment of incompatible pointer type'.
by: sumedh..... | last post by:
double * X size of X->?? size of X->?? double (*X) size of X->?? size of X->??
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
by: lllomh | last post by:
How does React native implement an English player?
by: Mushico | last post by:
How to calculate date of retirement from date of birth
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.