gpt4 book ai didi

c++ - 我正在编写一个日历来存储带有多个生日对象的生日我是迭代器的新手并且在使用 find() 时遇到编译器错误

转载 作者:行者123 更新时间:2023-11-28 07:38:41 26 4
gpt4 key购买 nike

I am making a calendar that stores birthdays in a multiset. The multiset actually stores birthday object pointers. I cant figure out how to use the find function with an iterator to pointers on a multiset

 MultiSet::MultiSet(string fName,string lName,int d,int m, int y):dateAndName(fName,lName,d,m,y)
{
}
void MultiSet::searchByName( Birthday *a)
{
multiset<Birthday *>::iterator result;
     *I am getting a compiler error on this next line it reads*
Error 1 error C2664: :
cannot convert parameter 1 from 'Birthday' to 'Birthday *const &.
     **

I am just not really sure how to use the find function with an iterator to pointers

**

    result=nameSet.find(&a);

if(result!=dateSet.end())
cout<<result->getFirstName();
else
cout<<"Person not found. "<<endl;
}
void MultiSet::addToList(Birthday *a)
{
nameSet.insert(a);
dateSet.insert(a);
}

最佳答案

您的 a 变量是指向 Birthday 的指针,而您的多重集包含指向 Birthday 的指针,因此不是:

nameSet.find(&a); // ERROR! nameSet is a container of Birthday*
// objects, and not of Birthday** objects

你应该这样做:

nameSet.find(a); // OK: Here you just look for a pointer to Birthday

关于c++ - 我正在编写一个日历来存储带有多个生日对象的生日我是迭代器的新手并且在使用 find() 时遇到编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16255212/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com