I need help understanding C++ syntax. I am referencing Derek Molloy Github,
/Chp08/i2c/cpp/I2CDevice.cpp
In his implementation file, he has this section in his code
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;
}
I am confused on this particular line,
if((this->file=::open(name.c_str(), O_RDWR)) < 0)
. What exactly does =::open
mean? I know the fstream library in C++ has an open method, but why include the ::
?