[英]How to reference struct string member?
I've struct: 我已经构造:
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;
}
When I reference gender by user.gender
, it says: 当我通过
user.gender
引用性别时,它说:
error: âstruct Datacratic::Optional<OpenRTB::User>â has no member named âgenderâ
result->segments.addStrings("gender", result->user.gender);
Thanks, Ann 谢谢,安
From the compiler error it looks to me like result->user
is of type OpenRTB::User
, which may be distinct from your struct User
class. 从编译器错误中,我看起来像
result->user
类型为OpenRTB::User
,可能与您的struct User
类不同。 So you to either make result->user
of your type User
, or extend the OpenRTB::User
class and add your additional fields. 所以,你要么使
result->user
您的类型的User
,或者扩展OpenRTB::User
类,并添加附加字段。 You could then access your fields from a OpenRTB::User *
by making a dynamic cast to User *
. 然后,您可以通过动态转换为
User *
从OpenRTB::User *
访问字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.