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;
}
The above is part of a code doing Linux I2C interface, my question is in the line:
this->file=::open(name.c_str(), O_RDWR)
I think this is trying to assign a value to the file descriptor this->file using open() function. But why there is a "::" symbol? Why not just "open()".