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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:39:55+00:00 2026-05-25T11:39:55+00:00

I have a situation where a class holds a vector of constant size 5.

  • 0

I have a situation where a class holds a vector of constant size 5. I need the data from the vector as an array of size 5 as our std::vector implementation doesn’t appear to use contiguous memory (please don’t argue about that, I know it should and we’ve checked it to death). The contiguous memory block is required so we can uuencode/uudecode the memory block easily (those turn an arbitrary memory block into a string).

I’m finding it difficult to return a statically sized array. I can do it by reference or I can do it by wrapping a statically sized array in a structure – but both are a little agitating. By reference requires the calling code to declare the array first and pass it in to the code, and the other option requires that I make an extra structure just for this purpose.

class A {
    public:
        /*return type*/ GetVectorAsArray(/*params*/) { /* implementation */ }

    private:
        std::vector<X> m_vec;
};

So, assuming I need to call GetVectorAsArray, what’s the cleanest way to return the 5 values in m_vec to the calling code? You can put whatever you want in return type or params and implementation.

  • 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-25T11:39:56+00:00Added an answer on May 25, 2026 at 11:39 am

    boost::array is intended for arrays of fixed size, you can always use that. It uses contiguous memory.

    Later edit: as correctly pointed out by commenters, std::array is available in the new standard.

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

Sidebar

Related Questions

So I have the following situation. I have a configuration class config.py that holds
What happens when I have the following situation: class A: holds on to dynamically
i have situation like this: class IData { virtual void get() = 0; virtual
Pseudo-situation: have a class (let's say BackgroundMagic ), and it has Start() and Stop()
I have the following situation : abstract class X { abstract X someMethod (...)
I have the following manager<->worker situation: class Manager { private: pthread_attr_t workerSettings; pthread_t worker;
I have following situation - Have a MongoService class, which reads host, port, database
I have a situation where I have an instanced class that needs to call
We have this situation: Window Keyboard ^ ^ | / ApplicationWindow so class Window
I have following situation. In a constructor of a pseudo class I attach a

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.