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

  • SEARCH
  • Home
  • 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 7173765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:53:34+00:00 2026-05-28T15:53:34+00:00

I am having trouble with an assignment. I have a class called Grid and

  • 0

I am having trouble with an assignment. I have a class called Grid and Record. Record is Grid that stores how many times each position in a Grid has been accessed. Grid must contain a data member of type Record that can store whenever a change is made to Grid. I’ve managed to avoid a circular dependancy, but I seem to have a problem with a “circular construction” leading to a stack overflow. Calling the Grid constructor makes a Record, which creates a Grid, which tries to make another Record and so on. My first thought was to make Grid’s Record data member a pointer which I initialize to NULL, then actually create the Record object outside of the constructor, however the assignment specifically says Grid’s Record data member must be of type Record, not a pointer to a Record. I am also not allowed to give Record a default constructor, so I’m guessing my implementation is wrong. Any suggestions for how I can solve this problem?

Record::Record(int rows, int cols) : grid(new Grid(rows, cols)) {};

Grid::Grid(int rows, int cols) : record(new Record(rows, cols)) {};
  • 1 1 Answer
  • 0 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-28T15:53:35+00:00Added an answer on May 28, 2026 at 3:53 pm

    I think there is simply a misunderstanding in the assignment, or that it was written poorly.

    It seems that what you want:

    Grid
    +---+---+-
    | a | b |
    +---+---+-
    | c | d |
    +---+---+-
    
    Record
    +---+---+-
    | 0 | 1 |
    +---+---+-
    | 2 | 2 |
    +---+---+-
    

    Which indicates that a has not been accessed and d has been accessed twice.

    Now, if a Grid should contain a Record to maintain its statistics, then a Record cannot be a Grid. As you noticed it is circular. However, Record is a grid. So I suspect there is a typo/reading issue here.

    My suggestion:

    class Record {
    public:
      Record(size_t rows, size_t cols): rows(rows), cols(cols), grid(rows*cols, 0) {}
    
    private:
      size_t rows;
      size_t cols;
      std::vector<size_t> grid;
    };
    
    
    template <typename E>
    class Grid {
    public:
      Grid(size_t rows, size_t cols): grid(rows*cols, 0), record(rows, cols) {}
    
    private:
      std::vector<E> grid;
      Record record;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a bit of trouble. I have an assignment that requires me to
I am having some trouble with my lab assignment for my CMPT class... I
I am having trouble with some theory. I have a model called Promos, and
I have an assignment in C++ and I'm having trouble getting started. The goal
I am writing a Date class for an assignment and I am having trouble
Having trouble with proper regex for RewriteCond RewriteCond %{REQUEST_URI} !^/foo/ Works as expected, that
Having Trouble with Entity Framework. I have been populating EntityReferences with an EntityKey inorder
I having trouble in dividing the HTML frames. I have been using the following
I am having trouble with IE7. I have a header, which is an IMG.
I'm trying to display a grid of items, with each item having a photo

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.