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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:42:09+00:00 2026-05-13T06:42:09+00:00

I have a class test which isn’t standard constructable nor assignable due to certain

  • 0

I have a class test which isn’t standard constructable nor assignable due to certain reasons. However it is copy constructable – on may say it behaves a bit like a reference.

Unfortunately I needed a dynamic array of these elements and realized that vector<test> isn’t the right choice because the elements of a vector must be standard constructable and assignable. Fortunately I got around this problem by

  • using vector<T>::reserve and vector<T>::push_back instead of vector<T>::resize and direct filling the entries (no standard construction)
  • the copy’n’swap trick for assignment and the fact that a vector is usually implemented using the Pimpl-idiom (no direct assignment of an existing test element), i.e

    class base {
    private:
        std::vector<test> vect;
        /* ... */
    public:
        /* ... */
        base& operator= (base y) {
            swap(y);
            return *this;
        }
        void swap(base& y) {
            using std::swap;
            swap(vect, y.vect);
        }
       /* ... */
    };
    

Now I assume that I probably didn’t considered every tiny bit and above all these tricks are strongly implementation dependent. The standard only guarantees standard behavior for standard constructable and assignable types.

Now what’s next? How can I get a dynamic array of test objects?

Remark: I must prefer built in solutions and classes provided by the standard C++.

Edit: I just realized that my tricks actually didn’t work. If I define a really* non assignable class I get plenty of errors on my compiler. So the question condenses to the last question: How can I have a dynamic array of these test objects?

(*) My test class provided an assignment operator but this one worked like the assignment to a reference.

  • 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-13T06:42:09+00:00Added an answer on May 13, 2026 at 6:42 am

    Edit: The below is no longer good practice. If your object supports moving then it will probably fit into a vector (see the std::vector elements requirements for details, in particular the changes for C++17).

    Consider using Boost’s ptr_vector, part of the Boost Pointer Container Library. See in particular advantage #3 in that library’s motivation.

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

Sidebar

Ask A Question

Stats

  • Questions 269k
  • Answers 269k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to call rand() each time you want a… May 13, 2026 at 1:22 pm
  • Editorial Team
    Editorial Team added an answer No, Visual Studio 2008 comes with SQL Server Express 2008.… May 13, 2026 at 1:22 pm
  • Editorial Team
    Editorial Team added an answer Is it okay to use many testing frameworks at once?… May 13, 2026 at 1:22 pm

Related Questions

Has anyone got any suggestions for unit testing a Managed Application Add-In for Office?
I have googled around and just found reams of pages about how to set
I'm a big fan of TDD and use it for the vast majority of
The question I have is this: If I have the MethodInfo object, for a
I wrote this simple test code, by adapting a piece from a book, to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.