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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:38:20+00:00 2026-06-17T19:38:20+00:00

Is it safe to have a std::array of dynamic object, for example std::array<std::string, 3>

  • 0

Is it safe to have a std::array of dynamic object, for example std::array<std::string, 3>, and to resize the contents (the strings) ? (because it can be problematic to have a raw C array of strings)

  • 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-17T19:38:21+00:00Added an answer on June 17, 2026 at 7:38 pm

    Yes, because std::array is a just a friendly template that wraps an underlying C style aray array. You can think of it as something like this:

    template <typename T, int size>
    class Array {
    ...
       T vals[size];
    }
    

    Change T to string above and you’ll quickly realize that anything that you can do to the contents of an array of strings you can do with a std::array of strings. This includes resizing, deleting, whatever you can imagine.

    To think even deeper about it, think about it this way. The std::array holds a string. The string has no idea where its being held. The array might tell the string to make a copy of itself (through a copy constructor or assignment), when say the array itself is assigned. However, this is its entirely through the string’s public interface. The fact that the string is being held by any data structure doesn’t limit that string’s functionality, it just makes the holder (in this case std::array) yet another client of the string‘s public interface.

    As containers like std::array need to work with a large variety of types, they tend to make relatively few typically well documented assumptions on the type T passed in. Stuff like requiring that T can be copy constructed, default constructed, and assigned. Then its typically up to the implementer* of T to ensure these few assumptions are valid.

    *There is a very advanced topic called template specialization where one could write a specialized version of array just for say “string”. Aside from vector<bool> these are pretty rare with the standard containers.

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

Sidebar

Related Questions

I have a std::map<std::string, myStruct> . It's safe to return address of a myStruct
Suppose I have: stl::map<std::string, Foo> myMap; is the following function thread safe? myMap[xyz] ?
I have this unsafe code that I need to make safe so it can
I have a text string that has been doctored to be web safe URLs
Some programming languages have support for strings, that are stored as folows: For example,
I have an std::vector. I want to copy the contents of the vector into
I have a structure like struct category { int id,newID; std::string name; }; and
I have an std::map < std::string, std::string > which is having values added to
Lets say I have a 2D array and this function: void addVec(std::vector<std::vector<short> >& arr,
As far as I know, std::string creates an identical array-copy of its content when

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.