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. Template overload of operator ++/--

Template overload of operator ++/--

Scheduled Pinned Locked Moved C / C++ / MFC
questioncsharpvisual-studiowpf
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.
  • T Offline
    T Offline
    Tydia kun
    wrote on last edited by
    #1

    I'd like to do an overlord of operator ++ and -- for my class with templates, like this: template<typename T> CValueHandler& operator ++ (); But the thing is, that while it compiles fine, I can't call that overloaded operator. SomeClass myClass; myClass++; Compiler simply complains it can't find a suitable overload. So, my question is, is it possible to overload ++/-- and use templates too? I can't seem to find a good place to fit in a template type either: SomeClass myClass; myClass<UINT64>++; Doesn't work either. Using Visual Studio 2005.

    N 1 Reply Last reply
    0
    • T Tydia kun

      I'd like to do an overlord of operator ++ and -- for my class with templates, like this: template<typename T> CValueHandler& operator ++ (); But the thing is, that while it compiles fine, I can't call that overloaded operator. SomeClass myClass; myClass++; Compiler simply complains it can't find a suitable overload. So, my question is, is it possible to overload ++/-- and use templates too? I can't seem to find a good place to fit in a template type either: SomeClass myClass; myClass<UINT64>++; Doesn't work either. Using Visual Studio 2005.

      N Offline
      N Offline
      Nelek
      wrote on last edited by
      #2

      Yes, you can overload operators in templates. Take a look into the template of Simon Hughes into the articles (keywords: Smart list). He overloaded operator =, +=, [], and I added the operator == for the lists. So it should be no problem to overload the ++ One thing that I had time ago was... I was using the ++ and the program was not running ok. I decided to try += 1, and still failed. The i used var = var + 1; and worked ok.

      Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you ;)

      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