I2CDevice::I2CDevice(unsigned int bus, unsigned int device) {
this->file=-1;
this->bus = bus;
this->device = device;
this->open();
}
int I2CDevice::open(){
string name;
if(this->bus==0) name = BBB_I2C_0;
else name = BBB_I2C_1;
if((this->file=::open(name.c_str(), O_RDWR)) < 0){
perror("I2C: failed to open the bus\n");
return 1;
}
if(ioctl(this->file, I2C_SLAVE, this->device) < 0){
perror("I2C: Failed to connect to the device\n");
return 1;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
上面是做Linux I2C接口的部分代码,我的问题是:
this->file=::open(name.c_str(), O_RDWR)
Run Code Online (Sandbox Code Playgroud)
我认为这是尝试使用 open() 函数为文件描述符 this->file 分配一个值。但为什么会有一个“::”符号呢?为什么不只是“open()”。
c++ ×1