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. Template again

Template again

Scheduled Pinned Locked Moved C / C++ / MFC
databasealgorithmshelpquestionlearning
4 Posts 3 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, The only reason I posted the whole code was to give one the chance to run the program and see in practice the problem. But I guess that is too much. Anyway, The implementation of the two functions is: [code] //It returns the member. 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->association_list[index]->linked_member(); searching=false; } else index++; else index++; if (searching && (index == LIST_SIZE)) { searching=false; } } return member; } [/code] [code] //it returns the book template Book* AssociationList::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; } [/code] The template file that I use to display the books is: [code] template void List::displayElement(char* type) { if (num_elements == 0) cout<<"No "<num_elements; element++) { cout<<'\n'; this->element_list[element]->display(association_list.get_member(element_list[element])); } } [/code] But it does not work for Members. I've tried to use the recommendations you've told me but it seems not to work. The program works ok, when I call the functions: book1.addElement("Books"); and book1.displayElement("Books"); to add a book and to display them respectively. But when I use the : member1.addElement("Member"); and member1.displayElement("Member"); it dispalys the problem: The compiler complains at the point: this->element_list[element]->display(association_list.get_member(element_list[element])); saying that : get_member: cannot convert parameter one from Class Member* to class Book*. Can you correct any mistakes or suggest any solutions? Please if you make any suggestion adjust them to my code, if possible. Best Regards, grscot

    N 1 Reply Last reply
    0
    • G grscot

      Dear all, The only reason I posted the whole code was to give one the chance to run the program and see in practice the problem. But I guess that is too much. Anyway, The implementation of the two functions is: [code] //It returns the member. 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->association_list[index]->linked_member(); searching=false; } else index++; else index++; if (searching && (index == LIST_SIZE)) { searching=false; } } return member; } [/code] [code] //it returns the book template Book* AssociationList::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; } [/code] The template file that I use to display the books is: [code] template void List::displayElement(char* type) { if (num_elements == 0) cout<<"No "<num_elements; element++) { cout<<'\n'; this->element_list[element]->display(association_list.get_member(element_list[element])); } } [/code] But it does not work for Members. I've tried to use the recommendations you've told me but it seems not to work. The program works ok, when I call the functions: book1.addElement("Books"); and book1.displayElement("Books"); to add a book and to display them respectively. But when I use the : member1.addElement("Member"); and member1.displayElement("Member"); it dispalys the problem: The compiler complains at the point: this->element_list[element]->display(association_list.get_member(element_list[element])); saying that : get_member: cannot convert parameter one from Class Member* to class Book*. Can you correct any mistakes or suggest any solutions? Please if you make any suggestion adjust them to my code, if possible. Best Regards, grscot

      N Offline
      N Offline
      Neville Franks
      wrote on last edited by
      #2

      Below the message editing area you will see a Formatting bar. You need to select all of your code and then click on "pre" and "code" to make it readable. Untill you start doing that your code examples are useless. Also short to the point snippets of code are far better than long winded examples. Neville Franks, Author of ED for Windows. www.getsoft.com Make money with our new Affilate program

      P 1 Reply Last reply
      0
      • N Neville Franks

        Below the message editing area you will see a Formatting bar. You need to select all of your code and then click on "pre" and "code" to make it readable. Untill you start doing that your code examples are useless. Also short to the point snippets of code are far better than long winded examples. Neville Franks, Author of ED for Windows. www.getsoft.com Make money with our new Affilate program

        P Offline
        P Offline
        peterchen
        wrote on last edited by
        #3

        ...however, you will have to turn your less than and greater than into HTML escapes, and avoid any smiley combination... unless things changed since I last tried to post code


        "Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
        sighist | Agile Programming | doxygen

        N 1 Reply Last reply
        0
        • P peterchen

          ...however, you will have to turn your less than and greater than into HTML escapes, and avoid any smiley combination... unless things changed since I last tried to post code


          "Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
          sighist | Agile Programming | doxygen

          N Offline
          N Offline
          Neville Franks
          wrote on last edited by
          #4

          peterchen wrote: ...however, you will have to turn your less than and greater than into HTML escapes, and avoid any smiley combination... unless things changed since I last tried to post code Yes you're right. The Formatting bar has options for this too. ie. < and > Neville Franks, Author of ED for Windows. www.getsoft.com Make money with our new Affilate program

          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