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;
}
else
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_register("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>
{
SQUADD_FUNC_PARAMS(0, 1, ".")

static int implementation(HSQUIRRELVM v)
{
Class * o;
SQUADD_SETUP_POINTER(o, 1)

// 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?
--
Regards,
Adam Dziendziel, Poland
Jul 23 '05 #1
1 4432
Thing that I have noticed:

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

// works
f = &sq_method<fs::path, 3334, ftype,
&fs::path::native_file_string>::implementation;

// 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

5
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
20
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...
27
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...
20
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){
20
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!
4
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...
4
by: code break | last post by:
Hi all, What is the difference between stack pointer and frame pointer ? Any suggestions are welcome ,,,
6
by: reji_thomas | last post by:
Hi, I have a doubt in the following code: struct xyz { int x; long l; float f; };
13
by: william | last post by:
code segment: long int * size; char entry; ............. size=&entry; ************************************* Gcc reported 'assignment of incompatible pointer type'.
34
by: sumedh..... | last post by:
double * X size of X->?? size of X->?? double (*X) size of X->?? size of X->??
0
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...
0
linyimin
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...
0
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...
0
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 ...
14
DJRhino1175
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...
0
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...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
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.