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. const type;

const type;

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 3 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.
  • B Offline
    B Offline
    Bo Hunter
    wrote on last edited by
    #1

    Is it possible to find out if a type was declared const? Thank You Bo Hunter

    M J 2 Replies Last reply
    0
    • B Bo Hunter

      Is it possible to find out if a type was declared const? Thank You Bo Hunter

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

      constness is a compile time hint.

      const int tata = 5;
      ...
      tata = 4; // you will get a compile error.


      Maximilien Lincourt Your Head A Splode - Strong Bad

      1 Reply Last reply
      0
      • B Bo Hunter

        Is it possible to find out if a type was declared const? Thank You Bo Hunter

        J Offline
        J Offline
        Joaquin M Lopez Munoz
        wrote on last edited by
        #3

        If you mean "writing generic code which knows whether a given type is const or not" you can have something like that:

        template <class T>
        my_generic_class
        {
        };

        // specialization for const types
        template<class T>
        my_generic_class<const T>
        {
        // implementation taking into account the type is const
        }

        Other than that, Boost.TypeTraits[^] features an utility called is_const which determines at compile time the constness of a type. I'm not sure if tihs is what you're after. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo Want a Boost forum in Code Project? Vote here[^]!

        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