473,404 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 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 4472
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.