Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSharedData and mutable members: Calling detach() from const method?
Forum Updated to NodeBB v4.3 + New Features

QSharedData and mutable members: Calling detach() from const method?

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 929 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.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #1

    My (implicitly shared) class has an error flag. I set this flag to indicate that the data within should not be further used.

    To keep my class at pointer size, I decided to put my error flag in my private data class, derived from QSharedData.

    Unfortunately, there are one or two cases where I recognize an error in a const method. The logical solution was to make my error flag mutable within the private data class. However, this is bound to break the detach mechanism.

    I could call detach myself in this case. However, detach is non-const.

    Would it be safe in such circumstances to cast away the constness of "this" (the class holding the private data class) in order to detach, before setting the error flag?

    (I should note that this would be my first const_cast in several 10000 lines of code. I'm no fan of them).

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved