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 question problem

Template question problem

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutoriallounge
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 would like to ask if it is possible to have a template function as a general function for two functions that have a different return type. For example: int AddNumbers(int a, int b); float AddFloats(float a, float b); What would it be the template function for the above example? Regards, grscot

    C 1 Reply Last reply
    0
    • G grscot

      Dear all, I would like to ask if it is possible to have a template function as a general function for two functions that have a different return type. For example: int AddNumbers(int a, int b); float AddFloats(float a, float b); What would it be the template function for the above example? Regards, grscot

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      template <class T> T Add(const T &a, const T&b)
      {
      return a + b;
      }

      Chris Losinger
      Smaller Animals Software

      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