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 9202539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:16:54+00:00 2026-06-17T23:16:54+00:00

I have searched for hours for a solution and tried different methods to address

  • 0

I have searched for hours for a solution and tried different methods to address my compilation errors related to unique_ptr and no copy/no assign. I even wrote a hidden copy and assign to prevent vector from calling it to no avail.

Here is the code causing the compilation errors:

class World{
    World(const World&) {}
    World& operator=(const World&) {return *this; }

    std::vector<std::vector<std::unique_ptr<Organism>>> cell_grid;
public:
    World() {
        cell_grid = std::vector<std::vector<std::unique_ptr<Organism>>> (20, std::vector<std::unique_ptr<Organism>> (20, nullptr));
    }
    ~World() {}
};

Compilation errors are related to the private member access issue.

  • 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-06-17T23:16:55+00:00Added an answer on June 17, 2026 at 11:16 pm

    The problem is the use of this vector constructor:

    vector(size_type n, const T& value);
    

    This constructor creates a vector of length n and each of the n elements has a copy of value. Since unique_ptr can not be copied (and neither can a vector<unique_ptr>), one can not use this constructor. Instead do this:

    World()
        : cell_grid(20)
    {
        for (auto& row : cell_grid)
            row.resize(20);
    }
    

    The first line calls the default constructor of vector<unique_ptr>, creating 20 size 0 vector<unique_ptr>s.

    The loop then resizes each of those vector<unique_ptr>s to have size == 20, with each element being a default constructed unique_ptr (which will have the value nullptr).

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

Sidebar

Related Questions

I have tried everything, searched the net for two hours or even more and
I have searched for hours now and haven't found a solution for my problem.
I have searched for a good couple hours now, looking for a solution to
I have searched the internet for countless hours looking for a solution and I
Very basic, and very annoying, I have searched solution for many hours with no
I have now searched for hours, but haven't found a solution yet. I hope
I've searched here and googled for hours, but have yet to find a solution
I have searched for hours however I still have no clue what is wrong
I have searched for hours for the answer to my question and have found
Up till now I have searched for hours on end and have not found

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.