Click here to Skip to main content
15,901,283 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Search a code MFC Pin
David Crow30-Apr-03 8:01
David Crow30-Apr-03 8:01 
Generaldialog box as a main window. Pin
sathyashrayan28-Apr-03 16:57
sathyashrayan28-Apr-03 16:57 
GeneralRe: dialog box as a main window. Pin
Ernest Laurentin28-Apr-03 18:29
Ernest Laurentin28-Apr-03 18:29 
GeneralRe: dialog box as a main window. Pin
Hans Dietrich28-Apr-03 18:35
mentorHans Dietrich28-Apr-03 18:35 
GeneralRe: dialog box as a main window. Pin
sathyashrayan28-Apr-03 21:27
sathyashrayan28-Apr-03 21:27 
GeneralHOWDOI: Enumerate Group Membership on Windows 98 Pin
Paul Farry28-Apr-03 15:50
professionalPaul Farry28-Apr-03 15:50 
GeneralRe: HOWDOI: Enumerate Group Membership on Windows 98 Pin
Brian Shifrin28-Apr-03 23:58
Brian Shifrin28-Apr-03 23:58 
GeneralMore templates problems Pin
grscot28-Apr-03 14:58
grscot28-Apr-03 14:58 
Dear all,I'm really sorry for asking again about the same thing, but I don't really undersatnd what's going on with the templates.

I've tried to use the template<class R, class P>
R* get_member(P* pArg)
as adviced, but it seems that my program is more complicated.
So, I think I have to submit you a significant part of my code to give me an extra help (and final one I hope ) to overcome this awful template obstacle.

AssociationList.h
template<class Book,class Member>
class AssociationList
{
public:
//It initialises all slots in the associationlist array to zero.
AssociationList();

/* It searches the associationlist, if book is found then returns
the member that is connected with.*/
//Member* get_member(Book* book);

/* It searches the associationlist, if member is found then returns
the book that is connected with.*/
//Book* get_book(Member* member);

template<class R,class P>
R* get_member(P* pArg);

/* Checks that book/member not already linked
creates association if objects are free to link
returns whether or not link was valid */
bool link(Book* book,Member* member);

/* Checks that book and member are linked
deletes association if they are linked
returns whether or not unlinking was valid */
bool unlink(Book* book,Member* member);
private:
Association<Book,Member>* association_list[LIST_SIZE];
};

AssociationList.cpp
template<class Book,class Member>
AssociationList<Book,Member>::AssociationList()
{
cout<<"AssociationList constructor called\n";
int index;

for(index=0; index<LIST_SIZE; index++)
this->association_list[index]=0;
}

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;
}


//template<class Book,class Member>
//Member* AssociationList::get_member(Book* book)

/*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;
}

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;
}*/

Association.h
template<class Book,class Member>
class Association
{
public:
//Sets up book and member with parameters
Association(Book* book, Member* member);

//Returns Book
Book* linked_book(){return this->book;}

//Returns Member
Member* linked_member(){return this->member;}

private:
Book* book;
Member* member;
};

Association.cpp
#ifndef _ASSOCIATIONCPP
#define _ASSOCIATIONCPP
#include "Association.h"

template<class Book,class Member>
Association<Book,Member>::Association(Book* book, Member* member)
{
this->book=book;
this->member=member;
}
#endif

Apologies for the huge amount of code.
grscot

GeneralRe: More templates problems Pin
HJo29-Apr-03 1:54
HJo29-Apr-03 1:54 
GeneralSquare control in MFC Dialog Pin
pitts28-Apr-03 13:23
pitts28-Apr-03 13:23 
GeneralRe: Square control in MFC Dialog Pin
Brian Shifrin28-Apr-03 14:24
Brian Shifrin28-Apr-03 14:24 
GeneralRe: Square control in MFC Dialog Pin
pitts29-Apr-03 3:28
pitts29-Apr-03 3:28 
GeneralRe: Square control in MFC Dialog Pin
Hans Dietrich28-Apr-03 18:49
mentorHans Dietrich28-Apr-03 18:49 
Generalanother template question Pin
grscot28-Apr-03 13:16
grscot28-Apr-03 13:16 
GeneralRe: another template question Pin
Phil Hamer28-Apr-03 13:33
Phil Hamer28-Apr-03 13:33 
GeneralCFile::Open access denied error Pin
IGx8928-Apr-03 12:35
IGx8928-Apr-03 12:35 
GeneralRe: CFile::Open access denied error Pin
Brian Shifrin28-Apr-03 13:07
Brian Shifrin28-Apr-03 13:07 
GeneralRe: CFile::Open access denied error Pin
IGx8929-Apr-03 12:42
IGx8929-Apr-03 12:42 
GeneralCHtmlCtrl Pin
Florin Ochiana28-Apr-03 10:49
Florin Ochiana28-Apr-03 10:49 
GeneralRe: CHtmlCtrl Pin
Brian Shifrin28-Apr-03 13:11
Brian Shifrin28-Apr-03 13:11 
GeneralEasy question but difficult answer Pin
VietDelphi28-Apr-03 9:53
VietDelphi28-Apr-03 9:53 
GeneralRe: Easy question but difficult answer Pin
John M. Drescher28-Apr-03 10:55
John M. Drescher28-Apr-03 10:55 
GeneralMDI question (when closing MDI Child windows) Pin
Maximilien28-Apr-03 9:29
Maximilien28-Apr-03 9:29 
GeneralRe: MDI question (when closing MDI Child windows) Pin
Brian Shifrin28-Apr-03 13:28
Brian Shifrin28-Apr-03 13:28 
GeneralTemplate question problem Pin
grscot28-Apr-03 8:21
grscot28-Apr-03 8:21 

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.