【发布时间】:2013-01-28 04:09:56
【问题描述】:
我在实现文件中有以下内容...
void ClientList::interestCompare(vector<string> intr)
{
for(int index = 0; index < intr.size(); index++)
{
this->interests[index];
}
}
这在规范文件中...
class ClientList
{
private:
// A structure for the list
struct ListNode
{
char gender;
string name;
string phone;
int numInterests; // The number of interests for the client
vector<string> interests; // list of interests
string match;
struct ListNode *next; // To point to the next node
};
//more stuff
...}
是否可以使用“this”指针访问结构中的“interests”向量?
如果是的话怎么做。
正如我现在所拥有的,我初始化一个 ListNode 指针指向 head 以便访问列表。我只是想知道“this”指针是否只能访问类的成员,或者它们是否可以访问嵌入在类中的更深层次的 ADT 变量。
这个问题有意义吗?
【问题讨论】:
-
您必须通过
ListNode的实例来访问它。拥有ClientList的实例并不一定意味着您拥有ListNode的实例。 -
*this在该函数的上下文中最好引用ClientList的成员变量而不是ClientList::ListNode。或者那是你缺少的那块? -
你能解释一下你想用interestCompare做什么吗?
-
我有两个不同的列表,男性和女性。兴趣比较();从客户那里接收兴趣向量,假设是男性,然后搜索女性 ClientList 对象以确定是否存在具有 3 个或更多匹配兴趣的客户。