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. Call a function on C++ object attribute change

Call a function on C++ object attribute change

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++
4 Posts 3 Posters 1 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.
  • V Offline
    V Offline
    vipin_nvk
    wrote on last edited by
    #1

    Hello I have a C++ class with few attributes and functions. Whenever a new value is assigned to a particular attribute (say the attribute is an integer variable in the class) a function should get called (triggered) and the piece of code inside the function should get executed. Is it possible? If yes, what is the mechanism. Please let me know. Thanx

    S 1 Reply Last reply
    0
    • V vipin_nvk

      Hello I have a C++ class with few attributes and functions. Whenever a new value is assigned to a particular attribute (say the attribute is an integer variable in the class) a function should get called (triggered) and the piece of code inside the function should get executed. Is it possible? If yes, what is the mechanism. Please let me know. Thanx

      S Offline
      S Offline
      SandipG
      wrote on last edited by
      #2

      Can't you make the member as private/protected and provide a Set method? Then inside Set method once variable is updated you can call the respective function.. Does it make sense..I hope it helps.

      Regards, Sandip.

      V C 2 Replies Last reply
      0
      • S SandipG

        Can't you make the member as private/protected and provide a Set method? Then inside Set method once variable is updated you can call the respective function.. Does it make sense..I hope it helps.

        Regards, Sandip.

        V Offline
        V Offline
        vipin_nvk
        wrote on last edited by
        #3

        Thanx Sandeep Simple and effective solution :) Regards, Vipin.

        1 Reply Last reply
        0
        • S SandipG

          Can't you make the member as private/protected and provide a Set method? Then inside Set method once variable is updated you can call the respective function.. Does it make sense..I hope it helps.

          Regards, Sandip.

          C Offline
          C Offline
          Code o mat
          wrote on last edited by
          #4

          Alternatively you could make wrapper classes for the members which on their = operator would call whatever is needed to be called.

          > The problem with computers is that they do what you tell them to do and not what you want them to do. <

          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