473,700 Members | 2,489 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<co nst char*>()
.def("native_fi le_string", &fs::path::nati ve_file_string)
;

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

// base template
template<typena me 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_setinstanceu p(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("co nstructor",
sq_constructor< Class, TypeTag, Sig>::implement ation

}

(...)
};

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

template<typena me 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_PAR AMS(0, 1, ".")

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

// sq_pushstring(v , o->*Method().c_st r(), -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(nam e, sq_method<Class , TypeTag, Sig, func>::implemen tation);

);
};

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 4505
Thing that I have noticed:

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

// works
f = &sq_method<fs:: path, 3334, ftype,
&fs::path::nati ve_file_string> ::implementatio n;

// doesn't work
ftype p = &fs::path::nati ve_file_string;
f = &sq_method<fs:: path, 3334, ftype, p>::implementat ion;

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
15934
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
6556
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 area of ram that's not reserved by the program. Accessing memory through such pointer is likely to result in core dump (memory access violation)"
27
2913
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 its values have to read and returned from this function. How do you use gets() for this? I just can't figure it out. Here is a bit of code
20
6231
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
1639
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
36176
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 makes integer from pointer without a cast driver.c:51: warning: assignment makes integer from pointer without a
4
14813
by: code break | last post by:
Hi all, What is the difference between stack pointer and frame pointer ? Any suggestions are welcome ,,,
6
2153
by: reji_thomas | last post by:
Hi, I have a doubt in the following code: struct xyz { int x; long l; float f; };
13
11989
by: william | last post by:
code segment: long int * size; char entry; ............. size=&entry; ************************************* Gcc reported 'assignment of incompatible pointer type'.
34
1898
by: sumedh..... | last post by:
double * X size of X->?? size of X->?? double (*X) size of X->?? size of X->??
0
8725
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9214
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8924
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7807
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6560
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5902
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4403
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3088
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2392
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.