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. Can't use template function to do 2 similar things(display member,book)

Can't use template function to do 2 similar things(display member,book)

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelplearning
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 am using the following function to display the members of a memberlist. I need also to display the books of a booklist. If I use the comments then there is no compilation problem, but I cant display the books, on the other hand if I do not use the comments there is a compilation problem because get_member() function does not accept class Member* argument, but only class Book* argument. How can I generalise the function to accept both arguments, and display both books and members using the same function? 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])); } } Regards, grscot

    V 1 Reply Last reply
    0
    • G grscot

      Dear all, I am using the following function to display the members of a memberlist. I need also to display the books of a booklist. If I use the comments then there is no compilation problem, but I cant display the books, on the other hand if I do not use the comments there is a compilation problem because get_member() function does not accept class Member* argument, but only class Book* argument. How can I generalise the function to accept both arguments, and display both books and members using the same function? 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])); } } Regards, grscot

      V Offline
      V Offline
      valikac
      wrote on last edited by
      #2

      Fix your template parameter to make it more understandable. I must see "template." Kuphryn

      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