【发布时间】:2017-10-24 12:55:26
【问题描述】:
我正在开发一个需要公开controller::open() 函数的控制c++ 库。但是在这个函数中,我必须调用POSIX::open() 函数来打开一个文件描述符。编译器抱怨我向控制器函数发送了无效参数并且不明白我想调用 POSIX open() 文件函数。
这是我的代码:
类声明:
class PosixReadController {
int open();
}
实现:
#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
int PosixReadController::open()
{
int fd = open("/dev/ttyf1", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
/*
* Could not open the port.
*/
perror("open_port: Unable to open /dev/ttyf1 - ");
}
else
fcntl(fd, F_SETFL, 0);
return fd;
}
错误信息(日食):
无效参数:'Candidates are: int open()'
使用::open 更改调用以打开到全局命名空间没有帮助。因为我看到库已经包含 open 函数并且我收到以下错误:
无效参数:'候选者是:int open(const char*, int, ...)
ImageCtrl* 打开(图像)''
有什么想法吗?
【问题讨论】:
-
您的环境中真的有
POSIX命名空间吗?还是只包含标准的<fcntl.h>POSIX 标头? -
哼,把你的问题相关的代码分享一下亲爱的1304怎么样?
-
很可能只是在全局范围内:
::open()。 -
在本站发布67个问题后,您应该知道需要显示相关代码和错误信息。
-
如果将
open("/dev/ttyf1", O_RDWR | O_NOCTTY | O_NDELAY);更改为::open("/dev/ttyf1", O_RDWR | O_NOCTTY | O_NDELAY);,是否会出现错误?如果有,那是什么?