Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3405850
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:33:21+00:00 2026-05-18T05:33:21+00:00

I have a 2-dimensional matrix of cells. Usually only invisible algorithms work with these

  • 0

I have a 2-dimensional matrix of cells. Usually only invisible algorithms work with these cells. But sometimes I want to visualize each cell so I added a pointer to a graphical object

class Cell
{
   ...
   QAbstractGraphicsItem* representation_;
   ...
}

The constructor of Cell sets representation_ to 0. Sometimes another Visualization class iterates on the matrix and adds elements to Cells that visualize the content of each cell by colors.

I think this breaks the RAII paradigma. Do you have a better approach?

I could create another 2-dimensional matrix and from there link to the original matrix so that the pointers are on the visualization side but I would need two matrices then.

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T05:33:22+00:00Added an answer on May 18, 2026 at 5:33 am

    RAII is misnamed, as (I think) Scott Meyers points out.

    It shouldn’t be called “Resource Acquisition is Initialization”, it should be called “Destruction is Resource Release”. But we are where we are.

    If the Cell “owns” the object pointed to by representation_, and deletes it in its destructor, then this is still a form of RAII, the same way that you can initialize a shared_ptr with a null pointer, then later set it to something else. I assume you use it correctly (ensure that the object is saved to some Cell or other immediately after it is created, with no chance of failure between the completion of the constructor and the storing of the pointer somewhere it will be eventually freed). If so, you’re using the important part of RAII, even though it’s not a constructor doing the work.

    It’s probably a violation of the single responsibility principle. You’ve made Cell responsible for representing a cell, and also for memory-managing this QAbstractGraphicsItem object. It would probably simplify things to change representation_ to a smart pointer type, so there’s no need for any special code in the destructor of Cell.

    If the Cell doesn’t “own” the object pointed to by representation_, then that doesn’t inherently violate RAII either, it just doesn’t implement it. Something else will have to be responsible for ownership of the object. Maybe that other thing uses RAII, maybe it violates it. For the thing to ensure the object lives as long as the Cell needs it, it would have to be involved somehow in the lifecycle of the Cell (for instance, if it owns the cell then you might be fine). So if it isn’t, there’s a good chance it’s violating RAII somehow.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a non-fixed dimensional matrix M, from which I want to access a
I have a multi-dimensional array, which basically consists of one sub-array for each year.
I have a multi dimensional array. The only actual values (other than other arrays)
I have an multi-dimensional array that I want to send to a PHP script
Possible Duplicate: How do I iterate through each element in an n-dimensional matrix in
I have a two-dimensional array: function getMatrix(size) { var matrix = []; for (var
I have X , a three-dimensional array in R. I want to take a
I have an unmanaged 2d array ( double A** ) representing a matrix. Each
i have a text file that holds a 2-dimensional matrix. it looks like the
I have a 3 dimensional grid, in which for each point of the grid

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.