Dear all,
I am fighting since some hours on migrating a libev C to a C++
implementation. For some unknown reasons, Visual Studio accepts a simple
function setting (ev::io iow; iow.set<io_cb_1>();), but not method settings
(iow2.set<myclass, &myclass::io_cb_2>(&Cobj) ;) !! VS does the same error
code on different VS version!
I fixed the VS compiling problem by either removing a method on ev++.h what
it seems to be a double declaration troubling the visual compiler or by
either modifying the no-argument callback method as showed below... But I
have no idea if this is what I have to do and if it will not create problem
later on!
from
void set (K *object) throw (){....}
to
void set () throw (){....}
should we then set a null instead of object ?
// no-argument callback
template <
class K,
void (K::*method)()>
void set () throw ()
{
set_ (NULL, method_noargs_thunk<K, method>);
}
Any feedbacks are welcomed warmly!
Many Thanks,
Rémi
//////////// from ev++.h /////////////////////////////
......
template<class K, void (K::*method)(watcher &w, int)>
static void method_thunk (EV_P_ ev_watcher *w, int revents)
{
(static_cast<K *>(w->data)->*method)
(*static_cast<watcher *>(w), revents);
}
#if 0
// no-argument callback
template <
class K,
void (K::*method)()>
void set (K *object) throw ()
{
set_ (object, method_noargs_thunk<K, method>);
}
#endif //0
template<class K, void (K::*method)()>
static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents)
{
(static_cast<K *>(w->data)->*method)
();
}
..........
//////////////////////////////////////////////////////////////////////
///////////////////////////////// THE PROG
/////////////////////////////////////////////////////////
#include "ev++.h"
#include <iostream>
#ifdef WIN32
#include <winsock2.h>
#include <io.h> //i.e. _open_osfhandle()
#include <fcntl.h> //i.e. _O_RDWR
#define FD_TO_SOCKET(fd) ((SOCKET) _get_osfhandle ((fd)))
#define SOCKET_TO_FD(fd) (_open_osfhandle (fd ,_O_RDWR)) //both read and
write
#define CLOSE_FD(fd) _close(fd)
#else // not WIN32
#include <sys/types.h>
#include <sys/socket.h>
......
#endif //WIN32
class myclass
{
public:
ev::io io;
void io_cb_2(ev::io &w, int revents) {};
myclass (int fd)
{
}
};
void io_cb_1 (ev::io &w, int revents) { }
int main()
{
SOCKET fd;
fd = ::socket(AF_INET, SOCK_STREAM, 0);
int fd_type = SOCKET_TO_FD(fd);
//type 1! // OK on Visual Studio, Cygwin and Linux
ev::io iow;
iow.set<io_cb_1>();
iow.start();
//type 2! KO on Visual Studio and OK on Cygwin and Linux
ev::io iow2;
myclass Cobj(fd_type);
iow2.set<myclass, &myclass::io_cb_2>(&Cobj) ;
iow2.start(fd_type, ev::READ);
std::cout << "coucou 3" << std::endl;
return 0;
}
/////////////////////////////// THE ERROR ON
VISUAL//////////////////////////////////////////////////////////////////////
1>Compiling...
1>mainCall.cpp
1>d:\developements\egox_ref\projects\libev++\ev++.h(357) : warning C4290:
C++ exception specification ignored except to indicate a function is not
__declspec(nothrow)
1>d:\developements\egox_ref\projects\libev++\ev++.h(381) : warning C4290:
C++ exception specification ignored except to indicate a function is not
__declspec(nothrow)
1>d:\developements\egox_ref\projects\libev++\ev++.h(813) : warning C4800:
'volatile sig_atomic_t' : forcing value to bool 'true' or 'false'
(performance warning)
1>d:\developements\egox_ref\projects\libev++\maincall.cpp(123) : error
C2440: 'specialization' : cannot convert from 'void (__thiscall myclass::*
)(ev::io &,int)' to 'void (__thiscall myclass::* const )(void)'
1> Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast
1>d:\developements\egox_ref\projects\libev++\maincall.cpp(123) : error
C2973: 'ev::base<ev_watcher,watcher>::set' : invalid template argument 'void
(__thiscall myclass::* )(ev::io &,int)'
1> with
1> [
1> ev_watcher=ev_io,
1> watcher=ev::io
1> ]
1> d:\developements\egox_ref\projects\libev++\ev++.h(493) : see
declaration of 'ev::base<ev_watcher,watcher>::set'
1> with
1> [
1> ev_watcher=ev_io,
1> watcher=ev::io
1> ]
1>d:\developements\egox_ref\projects\libev++\maincall.cpp(123) : error
C2668: 'ev::io::set' : ambiguous call to overloaded function
1> d:\developements\egox_ref\projects\libev++\ev++.h(468): could be
'void ev::base<ev_watcher,watcher>::set<myclass,void myclass::io_cb_2(ev::io
&,int)>(K *) throw()'
1> with
1> [
1> ev_watcher=ev_io,
1> watcher=ev::io,
1> K=myclass
1> ]
1> d:\developements\egox_ref\projects\libev++\ev++.h(493): or 'void
ev::base<ev_watcher,watcher>::set<myclass,void myclass::io_cb_2(ev::io
&,int)>(K *) throw()'
1> with
1> [
1> ev_watcher=ev_io,
1> watcher=ev::io,
1> K=myclass
1> ]
1> while trying to match the argument list '(myclass *__w64 )'
1>Build log was saved at
"file://d:\Developements\egoX_ref\projects\libev++\Debug\BuildLog.htm"
1>libev++ - 3 error(s), 3 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
_______________________________________________
libev mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev