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. Assignment of read only location, class with const method trying to write to private member variable [modified]

Assignment of read only location, class with const method trying to write to private member variable [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structures
3 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.
  • J Offline
    J Offline
    jeweladdict
    wrote on last edited by
    #1

    I'm stumped on this one I have a class, with a private unsigned char array. I have a class method which is const. It is trying to write to the private unsigned char array, but I get the assignment of read only location. I can't touch the headers/remove the const because it is an inherited virtual function. How do I access the unsigned char array?

    modified on Wednesday, May 6, 2009 12:40 PM

    S 1 Reply Last reply
    0
    • J jeweladdict

      I'm stumped on this one I have a class, with a private unsigned char array. I have a class method which is const. It is trying to write to the private unsigned char array, but I get the assignment of read only location. I can't touch the headers/remove the const because it is an inherited virtual function. How do I access the unsigned char array?

      modified on Wednesday, May 6, 2009 12:40 PM

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      jeweladdict wrote:

      private unsigned char array

      I presume it's private in your derived class (it's difficult to tell, as you haven't posted the code...). In that case, declare it as mutable. That way you can modify it even in a const method. However, unless (say) the array is a cache, is the design correct?

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      J 1 Reply Last reply
      0
      • S Stuart Dootson

        jeweladdict wrote:

        private unsigned char array

        I presume it's private in your derived class (it's difficult to tell, as you haven't posted the code...). In that case, declare it as mutable. That way you can modify it even in a const method. However, unless (say) the array is a cache, is the design correct?

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

        J Offline
        J Offline
        jeweladdict
        wrote on last edited by
        #3

        you sir, are a god :D Saved me a lot of coding...

        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