如何引用struct string成员?

时间:2016-05-31 22:08:42

标签: c++

我结构:

struct User {
~User();
Datacratic::Id id;                     ///< Exchange-specific user ID
Datacratic::Id buyeruid;               ///< Exchange seat-specific user ID
Datacratic::TaggedInt yob;             ///< Year of birth
std::string gender;             ///< Gender: Male, Female, Other
Datacratic::CSList keywords;           ///< List of keywords of consumer intent
Datacratic::UnicodeString customdata;         ///< Custom data from exchange
Datacratic::Optional<Geo> geo;                   ///< Geolocation of user at registration
std::vector<Data> data;         ///< User data segments
Json::Value ext;   
}

当我通过user.gender引用性别时,它会说:

error: âstruct Datacratic::Optional<OpenRTB::User>â has no member named âgenderâ
         result->segments.addStrings("gender", result->user.gender);

谢谢, 安

1 个答案:

答案 0 :(得分:0)

从编译器错误中我看起来result->user属于OpenRTB::User类型,可能与您的struct User类不同。因此,您要么result->user类型User,要么扩展OpenRTB::User类并添加其他字段。然后,您可以通过动态转换为OpenRTB::User *来访问User *中的字段。