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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:14:16+00:00 2026-06-09T21:14:16+00:00

I have a C++ function which returns a std::vector<float> . I am interfacing with

  • 0

I have a C++ function which returns a std::vector<float>.

I am interfacing with some C code.

How do I change this C++ function so that it returns some pointer to a float array, and how do I save this returned array so that I can use it in my C code?

  • 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-09T21:14:18+00:00Added an answer on June 9, 2026 at 9:14 pm

    You could save the returned temporary vector in a vector object with static storage duration.

    std::vector<float> foo()
    {
        return std::vector<float>();
    }
    
    float* call_foo_and_get_pointer()
    {
        static std::vector<float> save; // this line is executed only at the first
                                        // call to enclosing function
        save = foo();
        return save.data();  // or &data[0]
    }
    

    The pointer returned from call_foo_and_get_pointer is guaranteed to stay valid until the next call to it.

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

Sidebar

Related Questions

I have a (virtual) function which returns a std::vector with a single value. Let's
I have this function which returns a datatype InetAddress[] public InetAddress [] lookupAllHostAddr(String host)
So, I have a function which returns a pointer to a dynamically allocated double,
Please suppose I have a function that accepts a pointer as a parameter. This
I have a function in C++ that returns a vector<vector<double> > object. I have
I have a C++ function which returns a multi-line std::string . In the test-case
I have a function which returns a one-sided intersection of values between two input
I have a function which returns 3 numbers, e.g.: def numbers(): return 1,2,3 usually
If I have a function which returns a reference cursor for a query, how
Say, i have a function which returns a reference and i want to make

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.