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. another template question

another template question

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutoriallearning
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 've understood that the template function for the two functions : int AddNumbers(int a, int b); float AddFloats(float a, float b); is: template T Add(const T &a, const T&b) { return a+b; } because the arguments' return type is the same as the functions' return type. But what is the template function when the return type of the arguments is different from the return type of the function? For example: Member* get_member(Book* book); Book* get_book(Member* member); What is now the template function of the two above functions? Regards, grscot

    P 1 Reply Last reply
    0
    • G grscot

      Dear all, I 've understood that the template function for the two functions : int AddNumbers(int a, int b); float AddFloats(float a, float b); is: template T Add(const T &a, const T&b) { return a+b; } because the arguments' return type is the same as the functions' return type. But what is the template function when the return type of the arguments is different from the return type of the function? For example: Member* get_member(Book* book); Book* get_book(Member* member); What is now the template function of the two above functions? Regards, grscot

      P Offline
      P Offline
      Phil Hamer
      wrote on last edited by
      #2

      Your template function would have two parameters: template R* get_member(P* pArg); You could call it like: get_member(&book); get_member(&member);

      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