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. C++ class design question - static member

C++ class design question - static member

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++design
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.
  • I Offline
    I Offline
    Indrawati
    wrote on last edited by
    #1

    Hi I am currently building an app that maintains a number of objects of a certain class, and the app performs computationally heavy calculations to determine the state of each object. The state for each object is determined by a number of variables: e.g. variables A, B, C, and D. However, since some of the variables, e.g. variable A is actually identical for all objects, I am now implementing A as a private static variable with a public accessor function. This way, I think I can save some computation and storage space. My question is: is this the correct way to implement the class? Is building a base class and deriving from it better than my current solution? Thanks!

    M 1 Reply Last reply
    0
    • I Indrawati

      Hi I am currently building an app that maintains a number of objects of a certain class, and the app performs computationally heavy calculations to determine the state of each object. The state for each object is determined by a number of variables: e.g. variables A, B, C, and D. However, since some of the variables, e.g. variable A is actually identical for all objects, I am now implementing A as a private static variable with a public accessor function. This way, I think I can save some computation and storage space. My question is: is this the correct way to implement the class? Is building a base class and deriving from it better than my current solution? Thanks!

      M Offline
      M Offline
      maxsteel
      wrote on last edited by
      #2

      hi indrawati, in your case, the important thing is that what do your variables do. if there are required to be common for all the objects of the particular class, ie they share the same values, then u will have to use them as static. if this is the case then there should be no problem in the design

      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