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. Class Specific #define

Class Specific #define

Scheduled Pinned Locked Moved C / C++ / MFC
question
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.
  • C Offline
    C Offline
    Codin Carlos
    wrote on last edited by
    #1

    Hello all. I'd like to use something that approximates a Class Specific #define without using namespaces, static const's or enums. Actually enums in the class would be good except some of the defines are floating point numbers. 1 header file has #define MAX_LASER_POWER 23.3, another has #define MAX_LASER_POWER 44.0 Anybody have a clever way to elegantly encapsolate these defines? Thanks in advance!

    C 1 Reply Last reply
    0
    • C Codin Carlos

      Hello all. I'd like to use something that approximates a Class Specific #define without using namespaces, static const's or enums. Actually enums in the class would be good except some of the defines are floating point numbers. 1 header file has #define MAX_LASER_POWER 23.3, another has #define MAX_LASER_POWER 44.0 Anybody have a clever way to elegantly encapsolate these defines? Thanks in advance!

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

      Well, you could try this:

      class A
      {
      public:
      static const double MAX_LASER_POWER;
      };

      [EDIT] Oops, I forgot the "const".
      // In A's source file:
      const double A::MAX_LASER_POWER = 23.3;

      class B
      {
      public:
      static const double MAX_LASER_POWER;
      };

      [EDIT] Oops, I forgot the "const".
      // In B's source file:
      const double B::MAX_LASER_POWER = 44.0;

      You will get basically the same results as using a #define since they are const. Chris Richardson Programmers find all sorts of ingenious ways to screw ourselves over. - Tim Smith

      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