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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. optional/overloaded member function template parameter

optional/overloaded member function template parameter

Scheduled Pinned Locked Moved C / C++ / MFC
wpfhelp
2 Posts 1 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.
  • Z Offline
    Z Offline
    zildjohn01
    wrote on last edited by
    #1

    Is there any way to achieve the following syntax:

    typedef int nothrow;

    class my_class {
    public:
    template<typename T> void *search(int what);
    };

    template<typename T> void *my_class::search(int what) {throw "error";}

    template<> void *my_class::search<nothrow>(int what) {return 0;}

    int main() {
    my_class c;
    c.search<nothrow>(42); // OK!
    c.search(42); // not OK
    }

    MSVC8 "could not deduce the template argument for 'T'". I tried changing the declaration to template<typename T = void> void *search(int what); but unfortunately "default template arguments are only allowed on class templates." Thanks for your time.

    Z 1 Reply Last reply
    0
    • Z zildjohn01

      Is there any way to achieve the following syntax:

      typedef int nothrow;

      class my_class {
      public:
      template<typename T> void *search(int what);
      };

      template<typename T> void *my_class::search(int what) {throw "error";}

      template<> void *my_class::search<nothrow>(int what) {return 0;}

      int main() {
      my_class c;
      c.search<nothrow>(42); // OK!
      c.search(42); // not OK
      }

      MSVC8 "could not deduce the template argument for 'T'". I tried changing the declaration to template<typename T = void> void *search(int what); but unfortunately "default template arguments are only allowed on class templates." Thanks for your time.

      Z Offline
      Z Offline
      zildjohn01
      wrote on last edited by
      #2

      anyone?

      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