Unix Programming - Doubt about open() function used inside a C++ function.

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > April 2007 > Doubt about open() function used inside a C++ function.





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Doubt about open() function used inside a C++ function.
cviniciusm@gmail.com

2007-04-30, 1:17 am

Hello,

I'm using "g++ (GCC) 4.1.1 20070105 (Red Hat 4.1.1-51)".

I'm trying to use the open() function as defined by the header
fcntl.h, but I'm getting this error:
"
mylibrary.cpp:16: error: no matching function for call to
'mylibrary::open(const char*, int)'
mylibrary.cpp:14: note: candidates are: int mylibrary::open()
"

mylibrary.h:
class mylibrary
{
private:
int fd;
...
public:
int open(void);
...

};

mylibrary.cpp:
#include <fcntl.h>
#include "mylibrary.h"
int mylibrary::open(void)
{
fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NONBLOCK);
...
return 0;

}

How to tell the compiler to use the open() from fcntl.h, please?

TIA,
Vinicius.

sam_cit@yahoo.co.in

2007-04-30, 1:17 am

On Apr 30, 6:55 am, cvinici...@gmail.com wrote:
> Hello,
>
> I'm using "g++ (GCC) 4.1.1 20070105 (Red Hat 4.1.1-51)".
>
> I'm trying to use the open() function as defined by the header
> fcntl.h, but I'm getting this error:
> "
> mylibrary.cpp:16: error: no matching function for call to
> 'mylibrary::open(const char*, int)'
> mylibrary.cpp:14: note: candidates are: int mylibrary::open()
> "
>
> mylibrary.h:
> class mylibrary
> {
> private:
> int fd;
> ...
> public:
> int open(void);
> ...
>
> };
>
> mylibrary.cpp:
> #include <fcntl.h>
> #include "mylibrary.h"
> int mylibrary::open(void)
> {
> fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NONBLOCK);
> ...
> return 0;
>
> }
>
> How to tell the compiler to use the open() from fcntl.h, please?
>
> TIA,
> Vinicius.


any reason as to why you are having the same name open() for your
custom member function of the class?

Barry Margolin

2007-04-30, 1:17 am

In article <1177898133.107010.322600@y80g2000hsf.googlegroups.com>,
cviniciusm@gmail.com wrote:

> Hello,
>
> I'm using "g++ (GCC) 4.1.1 20070105 (Red Hat 4.1.1-51)".
>
> I'm trying to use the open() function as defined by the header
> fcntl.h, but I'm getting this error:
> "
> mylibrary.cpp:16: error: no matching function for call to
> 'mylibrary::open(const char*, int)'
> mylibrary.cpp:14: note: candidates are: int mylibrary::open()
> "
>
> mylibrary.h:
> class mylibrary
> {
> private:
> int fd;
> ...
> public:
> int open(void);
> ...
>
> };
>
> mylibrary.cpp:
> #include <fcntl.h>
> #include "mylibrary.h"
> int mylibrary::open(void)
> {
> fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NONBLOCK);
> ...
> return 0;
>
> }
>
> How to tell the compiler to use the open() from fcntl.h, please?


fd = ::open(...);

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com