473,387 Members | 1,548 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,387 software developers and data experts.

Wrapping C functions in C++

Hi Folks,

I want to wrap the Unix socket library in a C++ class and am having the
following difficulty. I have a method in my C++ class named connect and
within this method I want to call the Unix socket connect function. The
problem is that the compiler complains:

.../common/Socket.h:71: error: no matching function for call to
âSocket::connect(int&, sockaddr*&, int&)â
.../common/Socket.h:37: note: candidates are: void Socket::connect(const
char*, int)

Notice that it is looking within my Socket class for connect(int, sockaddr,
int), but it really should be looking in the C-based socket library. What
I've done as a kludgy fix is to create a forwarding function:

fConnect(int, sockaddr, int) {
connect(int, sockaddr, int);
}

class Socket {
connect() {
fConnect(int, sockaddr, int);
}
}

But I find this to be ugly. Is there a better way to accomplish this,
perhaps my simply specifying which connect I want to call within the class,
instead of having to deal with renaming things?

Thank you.
Sep 28 '06 #1
4 2426
Anonymous wrote:
class Socket {
connect() {
fConnect(int, sockaddr, int);
}
}
This has nothing to do with connect being a C function.
It has entirely everything to do with names in different
scopes. Inside Socket::connect() the lookup yields
Socket::connect(). If you want the global namespace
connect, all you do is add the scope resolution operator:
connect() {
::connect(int, sockaddr, int);
}
Sep 28 '06 #2
On Thu, 28 Sep 2006 06:14:31 -0500, "Anonymous" <An*******@home.net>
wrote:
>Hi Folks,

I want to wrap the Unix socket library in a C++ class and am having the
following difficulty. I have a method in my C++ class named connect and
within this method I want to call the Unix socket connect function.
<...>
>
class Socket {
connect() {
fConnect(int, sockaddr, int);
use instead:
::connect(int,sockaddr,int);
}
}
This tells the compiler tyo look for connect at the global scope.

Once you have corrected all errros that will arise from trying to use
the token "int" as parameter to call a function and some similiar
ones... you will have your connect function working.

Zara
Sep 28 '06 #3
Anonymous wrote:
Hi Folks,

I want to wrap the Unix socket library in a C++ class and am having the
following difficulty. I have a method in my C++ class named connect and
within this method I want to call the Unix socket connect function. The
problem is that the compiler complains:

../common/Socket.h:71: error: no matching function for call to
âSocket::connect(int&, sockaddr*&, int&)â
../common/Socket.h:37: note: candidates are: void Socket::connect(const
char*, int)

Notice that it is looking within my Socket class for connect(int, sockaddr,
int), but it really should be looking in the C-based socket library. What
I've done as a kludgy fix is to create a forwarding function:

fConnect(int, sockaddr, int) {
connect(int, sockaddr, int);
}

class Socket {
connect() {
fConnect(int, sockaddr, int);
}
}

But I find this to be ugly. Is there a better way to accomplish this,
perhaps my simply specifying which connect I want to call within the class,
instead of having to deal with renaming things?
Yes, explcitly qualify the socket's connect function as being in the
global namespace:

::connect( someInt, someAddr, someOtherInt );

Cheers! --M

Sep 28 '06 #4
Anonymous wrote:
Hi Folks,

I want to wrap the Unix socket library in a C++ class and am having the
following difficulty. I have a method in my C++ class named connect and
within this method I want to call the Unix socket connect function.
try ::connect() to call the global function.

-Martin
Sep 29 '06 #5

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

Similar topics

13
by: Roy Smith | last post by:
I've got a C library with about 50 calls in it that I want to wrap in Python. I know I could use some tool like SWIG, but that will give me a too-literal translation; I want to make some...
5
by: nimdez | last post by:
Hi, I am working on an existing code base in which a lot of data displayed to the user is formatted in tables. Most tables are printed row-by-row using printf() with "%s" print conversion...
2
by: dam_fool_2003 | last post by:
My understanding about wrapping is that we add utilities to a lib function for our specific use. So days ago in the c.l.c I saw a function def as: void * xmalloc (size_t size) { register void...
1
by: John Lee | last post by:
Hi, I understand we could use p/Invoke to access most of the C/C++ DLL but there are some cases the functions can only be accessed by C/C++ so it would be good if I could create a .NET class to...
5
by: Lee Crabtree | last post by:
More fun wrapping unmanaged code... I have a class heirarchy that I need to expose to C#, so I need to wrap all the classes. That's not a big deal, except for the base class, which is abstract....
10
by: Tom the Canuck | last post by:
What would be the best way to proceed? Should I make a pure virtual class and then derive from that? I want the base class to have functions defined so that I don't have to do the work all over...
6
by: Gerhard Prilmeier | last post by:
Hello, I have an unmanaged C++ API that uses virtual functions, like this: class A { public: virtual void handleMe(){} };
3
by: gabriel.becedillas | last post by:
Hi, I'm having problems wrapping a hierarchy of classes, actually having problems wrapping the base class. I don't need to use the WrapClass mechanism since I don't want to override classes in...
8
by: Anish Chapagain | last post by:
Hi!! I tried wrapping a simple C code suing SWIG to Python, but am having problem, my .c file is, Step 1: example.c -------------- double val=3.0; int fact(int n)
5
by: Charlie | last post by:
Hi All, I am new to using swig/C++/python. I got some problem with function pointers. I posted in swig-user, but got no response. So I forwarded it here. You help is greatly appreciated. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.