I am currently working on a project for school. The code that I'm creating is a bank account system. To access different members, I am having the user input their member ID which gets passed as one of the parameters to a function called findMember
.
Here's the function:
int findMember(vector<Member> patron, int memID)
{
int vectorSize;
vectorSize = patron.size();
for (int index = 0; index < vectorSize; index++)
{
if (memID == patron[index].getMemberID())
return index;
}
}
Here's the vector:
vector<Member*> patron; // Vector to store the members.
Here's the function call:
int acctID, memberIndex;
cout << "Enter your Account ID: ";
cin >> acctID;
memberIndex = findMember(patron, acctID); // Helps find the index if the current stored member.
patron[memberIndex]->menu(); // Opens the current members
storage location.
The error codes are these:
Error (active) E0312 no suitable user-defined conversion from "std::vector<Member *, std::allocator<Member *>>" to "std::vector<Member, std::allocator<Member>>" exists
Error C2664 'int findMember(std::vector<Member,std::allocator<_Ty>>,int)': cannot convert argument 1 from 'std::vector<Member *,std::allocator<_Ty>>' to 'std::vector<Member,std::allocator<_Ty>>'
I have looked around the web for E0312 with no luck finding the reason why it gets thrown. C2664 had the same results. Where am I going wrong with my code?
Also, thanks in advance.
Thanks @2785528 for the response.
I was being inconsistent with the way I was passing the vector<Member*>
. Once that error was fixed, all that was needed to be done was to change patron[index].getMemberID()
to patron[index]->getMemberID()
.
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.