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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:52:12+00:00 2026-05-26T21:52:12+00:00

std::vector<float> someOp(void) { using namespace std; vector<float> results; // some operations done to results

  • 0
std::vector<float> someOp(void)
{
    using namespace std;
    vector<float> results;
    // some operations done to results
    return results;
}

int main(void)
{
    using namespace std;
    vector<float> &results = someOp();
}

Does the vector returned by someOp exist in the someOp() stack space or in the main() stack space?

I’m inclined to believe that it doesn’t get copied/moved to the main() stack space since the results vector has the same address inside of both methods.

  • 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-26T21:52:13+00:00Added an answer on May 26, 2026 at 9:52 pm

    Neither, that’s not valid C++ (and doesn’t get compiled by g++).

    It seems you’re trying to store a reference to the returned results, but that’s impossible as the returned results exists in the stack frame of someOp, and, while it will still be there just after someOp() returns, will get overwritten at some point in the future.

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

Sidebar

Related Questions

I use the following algorithm to generate polygon outlines: void OGLSHAPE::GenerateLinePoly(std::vector<DOUBLEPOINT> &input, int width)
If in C++/cli I write ref class test { void method() {< std::vector<float> my_stack_vector;
Given std::vector<CMyClass> objects; CMyClass list[MAX_OBJECT_COUNT]; Is it wise to do this? for(unsigned int i
I have a std::vector<int> , and I want to delete the n th element.
I have a std::vector that holds a Point struct (x,y,z and some other non-pointer
struct Vector { float i,j,k; } std::vector pt[size]; ... = ... + pt[temp]; temp
There is a vector of vectors: std::vector <std::vector <float> > VoV; VoV.resize(num); // num
There are 2 unsorted vectors of int and vector of pairs int, int std::vector
std::vector sure is great, hey? I'm getting an EXC_BAD_ACCESS in using push_back to add
I got a compiling error when using std::copy to convert a 1D vector to

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.