Suppose I have this composition:
class Dataset
{
std::unique_ptr<Properties> properties;
std::unique_ptr<Properties> & getProperties() { return properties; }
Dataset & getDataset() { return *this }
....
}
class Properties
{
Property & operator[](const std::string & s);
...
}
How do I call the operator[]? And why is the following a syntax error?
getDataset().getProperties()->["Key"]
// syntax error
getDataset().getProperties()->operator[]("Key");
要么
(*getDataset().getProperties())["Key"];
我会比较喜欢:
(*getDataset().getProperties())["Key"];
There are at least two approaches
( *getDataset().getProperties() )["Key"]
getDataset().getProperties()->operator []( "Key" )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.