Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. More templates problems

More templates problems

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasewpfalgorithmsdata-structures
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    grscot
    wrote on last edited by
    #1

    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 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 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 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* association_list[LIST_SIZE]; }; AssociationList.cpp template AssociationList::AssociationList() { cout<<"AssociationList constructor called\n"; int index; for(index=0; indexassociation_list[index]=0; } template R* AssociationList::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 //Member* AssociationList::get_member(Book* book) /*Member* AssociationList::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->asso

    H 1 Reply Last reply
    0
    • G grscot

      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 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 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 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* association_list[LIST_SIZE]; }; AssociationList.cpp template AssociationList::AssociationList() { cout<<"AssociationList constructor called\n"; int index; for(index=0; indexassociation_list[index]=0; } template R* AssociationList::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 //Member* AssociationList::get_member(Book* book) /*Member* AssociationList::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->asso

      H Offline
      H Offline
      HJo
      wrote on last edited by
      #2

      What is wrong with (.h) Member* get_member(Book* book); (.cpp) template<class Book,class Member> Member* AssociationList::get_member(Book* book) { ... } ?

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups