Maps

I want to pair two objects together by the isbn of the book and the member id of the member but im getting an error, im doing the pairing wrong, could someone please help me out?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "BinarySearchTreeBooks.h"
#include "BinarySearchTreeMembers.h"
#include <map>

typedef map <BookType, MemberType > bookMap;
typedef pair<BookType, MemberType> bookPair;
typedef bookMap::iterator bItr;
typedef bookMap::const_iterator cItr;


int main(){
	BstBooks bRoot;
	BookType book[5];
	BstBooks *bNode;
	BookType *bookP;
	
	BstMembers mRoot;
	BstMembers* mNode;
	MemberType mem[2];
	MemberType* memP;
	
	bookMap bMap;
	
	string a[3]={"Jim", "Merlin", "Kir"};
	
	//b=new BookType;
	book[0].SetTitle("Narnia");book[0].SetAuthor(a, 3);book[0].SetPublisher("Alexis");book[0].SetISBN(123);book[0].SetPrice(4.99);book[0].SetCopies(5);book[0].SetNrOfAuth(3);
	book[1].SetTitle("Harry Potter");book[1].SetAuthor(a, 3);book[1].SetPublisher("Star");book[1].SetISBN(134);book[1].SetPrice(4.99);book[1].SetCopies(5);book[1].SetNrOfAuth(3);
	book[2].SetTitle("Lord Of The Rings");book[2].SetAuthor(a, 3);book[2].SetPublisher("Candy");book[2].SetISBN(133);book[2].SetPrice(4.99);book[2].SetCopies(5);book[2].SetNrOfAuth(3);
	
	mem[0].SetName("Jimmy");mem[0].SetId(1234);
	mem[1].SetName("Thomas");mem[1].SetId(1234);
	
	for (int i=0; i<3; i++) {
		bRoot.insertBook(bNode, book[i]);
		//cout << i;
	}
	for (int x=0; x<2; x++) {
		mRoot.insertMember(mNode, mem[x]);
	}

	//root.postOrderBooks(newNode);
	long isbn, memId;
	//cout << "enter Isbn to remove, -1 to quit" << endl;

	//cin >> key;
	//root.removeBook(newNode, key);
	
	bRoot.inOrderBooks(bNode);
	cout << "enter Isbn to search for book, -1 to quit" << endl;

	cin >> isbn;
	bRoot.searchBooks(bNode, isbn, bookP);
	
	cout << *bookP;
	
	mRoot.inOrderMembers(mNode);
	
	cout << "enter mem id of person to borrow book";
	cin >> memId;
	mRoot.searchMembers(mNode, memId, memP);
	
	bMap.insert(bookPair(bookP->GetISBN(), memP->GetMemId()));
	
	return 0;
}
What is the error?
no matching call to std::pair<BookType, MemberType> pair(long int, long int) on line 63
what can i do?
Last edited on
Well, you defined bookPair as a pair of BookType and MemberType and then tried to construct a pair from two integers. It should probably be bookPair(*bookP, *memP)
but my problem is that im send in a pointer by refrence *&memP and *&bookP so it gives me another error, how can i solve this?
Last edited on
Sorry. I really don't understand what you are saying...
closed account (Lv0f92yv)
If you copy the errors you see to this board, people here could help more... From the sounds of things, your issue now is compiler errors, not run time bugs, correct?
Ok, my error after doing what hamsterman suggested is:

no matching function for call to 'std::pair<BookType, MemberType>::pair(BookType*&, MemberType*&)'

because in my search function im passing in bookP by pointer reference:

bool searchBooks(BstBooks *&root, long &key, BookType *& b);

i hope that makes more sense


Last edited on
Is the error still from line 63?
yes,
i tried to change the search function to return a pointer and do what you suggested but still same error?
im using Xcode, could it be something to do with that?
If the error is on line 63, so why would you change the search function used on line 53?

Post the headers. I'll try compiling this myself..
isbn appears to be long

if BookType is not an alias for long, you may have problems due to GetISBN() not returning BookType
Thanks for all the help i solved it...

i defined the map differently, actually more to what i wanted to do:

1
2
 typedef map <long, MemberType> bookMap;
typedef pair<long, MemberType> bookPair; 


and then used:

1
2
3
bMap.insert(bookPair(bookP->GetISBN(), *memP));
	
	MemberType member = bMap[bookP->GetISBN()];


simple silly mistakes, sorry for the inconvinence
Thanks hamsterman, kfmfe04 and desh for all your help
Topic archived. No new replies allowed.