Click here to Skip to main content
15,899,754 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Small CString question. Pin
David Crow29-Apr-03 5:19
David Crow29-Apr-03 5:19 
GeneralRe: Small CString question. Pin
Hans Dietrich29-Apr-03 5:28
mentorHans Dietrich29-Apr-03 5:28 
QuestionHow to create a process with a different name? Pin
Chen Venkataraman29-Apr-03 4:17
Chen Venkataraman29-Apr-03 4:17 
AnswerRe: How to create a process with a different name? Pin
David Crow29-Apr-03 5:23
David Crow29-Apr-03 5:23 
AnswerRe: How to create a process with a different name? Pin
basementman29-Apr-03 6:41
basementman29-Apr-03 6:41 
GeneralRe: How to create a process with a different name? Pin
Chen Venkataraman29-Apr-03 9:01
Chen Venkataraman29-Apr-03 9:01 
GeneralRe: How to create a process with a different name? Pin
Dave Kreskowiak29-Apr-03 9:29
mveDave Kreskowiak29-Apr-03 9:29 
GeneralTemplate question Pin
grscot29-Apr-03 3:32
grscot29-Apr-03 3:32 
Dear all,
I have two functions:
a) Member* get_member(Book* book);
b)Book* get_book(Member* member);

The implementation code for the function prototypes is:

a)
template<class Book,class Member>
Member* AssociationList<Book,Member>::get_member(Book* book)
{
Member* member=0;
bool searching=true;
int index=0;

while(searching)
{
if (this->association_list[index])
if (this->association_list[index]->linked_book()==book)
{
member=this->association_list[index]->linked_member();
searching=false;
}
else
index++;
else
index++;
if (searching && (index == LIST_SIZE))
{
searching=false;
}
}
return member;
}

b)
template<class Book,class Member>
Book* AssociationList<Book,Member>::get_book(Member* member)
{
Book* book=0;
bool searching=true;
int index=0;

while(searching)
{
if (this->association_list[index])
if (this->association_list[index]->linked_member()==member)
{
book=this->association_list[index]->linked_book();
searching=false;
}
else
index++;
else
index++;
if (searching && (index == LIST_SIZE))
{
searching = false;
}
}
return book;
}

All I want to do is use one generic function for the two, so that from the main.cpp:

void main()
{
List<Member>member1;
List<Book>book1;
char menuChoice;
do
{
cout<<'\n';
cout<<'\n';
cout<<"**** Main Menu ****"<<endl;
cout<<'\n';
cout<<"1: Add Book "<<endl;
cout<<'\n';
cout<<"2: Remove Book "<<endl;
cout<<'\n';
cout<<"3: Display Books "<<endl;
cout<<'\n';
cout<<"4: Add Member "<<endl;
cout<<'\n';
cout<<"5: Remove Member "<<endl;
cout<<'\n';
cout<<"6: Display Members "<<endl;
cout<<'\n';
cout<<"7: Borrow Book "<<endl;
cout<<'\n';
cout<<"8: Return Book "<<endl;
cout<<'\n';
cout<<"0: Quit "<<endl;
cout<<endl;
cout<<"Enter one of the above choices: ";cinFlush;
cin>>menuChoice;
switch(menuChoice)
{
case '1': cout<<'\n';
book1.addElement("Books");
break;
case '2': cout<<'\n';

break;
case '3': cout<<'\n';
book1.displayElement("Books");
break;
case '4': cout<<'\n';
/*member1.addElement("Member");*/
break;
case '5': cout<<'\n';

break;
case '6': cout<<'\n';
/*member1.displayElement("Member");*/
break;
case '7': cout<<'\n';
//book1.borrowElement();
break;
case '8': cout<<'\n';
//book1.returnElement();
break;
default: cout<<'\n';
cout<<"Invalid Selection\n";
}
}while(menuChoice != '0' && !cin.eof());
prompt_to_quit();
}

...to call each one and dispaly either the books from a book array or the members from a member array.
The'display' implementation code is:
template<class Object>
void List<Object>::displayElement(char* type)
{
if (num_elements == 0)
cout<<"No "<<type<<" is found in the "<<type<<" array.\n";
else
for(int element=0; element<this->num_elements; element++)
{
cout<<'\n';
this->element_list[element]->display(association_list.get_member(element_list[element]));
}
}

But I'm having some errors trying to use
template<class R,class P>
R* get_member(P* pArg); instead of using the a,b function prototypes. The 'generic' function that I use and causes the problems is:
template<class R,class P>
R* AssociationList<Book,Member>::get_member(P* pArg)
{
R* member=0;
bool searching=true;
int index=0;

while(searching)
{
if (this->association_list[index])
if (this->association_list[index]->linked_book()==book)
{
member=this->association_list[index]->linked_member();
searching=false;
}
else
index++;
else
index++;
if (searching && (index == LIST_SIZE))
{
searching=false;
}
}
return member;
}
The errors are:
'AssociationList<class Book, class Member>::get_member':unable to resolve function overload
and the second one is:
template definitions cannot nest(??)

Could someone help me?
Regards,
grscot



GeneralODBC, SqlGetData Pin
justin22329-Apr-03 3:01
justin22329-Apr-03 3:01 
GeneralRe: ODBC, SqlGetData Pin
Pavel Klocek29-Apr-03 5:29
Pavel Klocek29-Apr-03 5:29 
GeneralRe: ODBC, SqlGetData Pin
justin22329-Apr-03 5:55
justin22329-Apr-03 5:55 
GeneralSerialization Pin
Brigg Thorp29-Apr-03 2:12
Brigg Thorp29-Apr-03 2:12 
GeneralRe: Serialization Pin
Nick Parker29-Apr-03 2:47
protectorNick Parker29-Apr-03 2:47 
GeneralRe: Serialization Pin
Brigg Thorp29-Apr-03 3:09
Brigg Thorp29-Apr-03 3:09 
GeneralRe: Serialization Pin
Nick Parker29-Apr-03 4:48
protectorNick Parker29-Apr-03 4:48 
GeneralSuggestion: Serialization Pin
Joan M29-Apr-03 4:42
professionalJoan M29-Apr-03 4:42 
GeneralQuestion about size_type and const_iterator of vector. Pin
George229-Apr-03 1:46
George229-Apr-03 1:46 
GeneralRe: Question about size_type and const_iterator of vector. Pin
jhwurmbach29-Apr-03 2:17
jhwurmbach29-Apr-03 2:17 
GeneralRe: Question about size_type and const_iterator of vector. Pin
George229-Apr-03 2:50
George229-Apr-03 2:50 
GeneralRe: Question about size_type and const_iterator of vector. Pin
markkuk29-Apr-03 3:18
markkuk29-Apr-03 3:18 
GeneralRe: Question about size_type and const_iterator of vector. Pin
George229-Apr-03 3:40
George229-Apr-03 3:40 
GeneralDisappearing folders in Visual Studio Pin
Poul Haahr Klemmensen28-Apr-03 23:38
Poul Haahr Klemmensen28-Apr-03 23:38 
GeneralRe: Disappearing folders in Visual Studio Pin
HJo29-Apr-03 0:17
HJo29-Apr-03 0:17 
GeneralRe: Disappearing folders in Visual Studio Pin
Poul Haahr Klemmensen29-Apr-03 2:11
Poul Haahr Klemmensen29-Apr-03 2:11 
GeneralRe: Disappearing folders in Visual Studio Pin
Bartosz Bien29-Apr-03 2:36
Bartosz Bien29-Apr-03 2:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.