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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:29:53+00:00 2026-06-10T09:29:53+00:00

Possible Duplicate: Can I call functions that take an array/pointer argument using a std::vector

  • 0

Possible Duplicate:
Can I call functions that take an array/pointer argument using a std::vector instead?

I recently came across something like this:

class X {
    public: void foo(float* p, int elements);
};

= a method that expects an array of float values.

But in the example code this was the way they used it:

std::vector<float> bar;
bar.push_back(42);
// ...

X x;
x.foo( &bar[0], (int)bar.size() );

Now I’m wondering whether this is a safe method or just happens to work with most implementations of std::vector? (maybe this is an operator-overloading thing? I’m not yet that confident with this stuff..)

  • 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-10T09:29:54+00:00Added an answer on June 10, 2026 at 9:29 am

    Yes, it’s safe.

    n3337 23.3.6.1/1. In C++03 standard this is 23.2.4/1

    A vector is a sequence container that supports random access iterators. In addition, it supports (amortized)
    constant time insert and erase operations at the end; insert and erase in the middle take linear time. Storage
    management is handled automatically, though hints can be given to improve efficiency. The elements of a
    vector are stored contiguously
    , meaning that if v is a vector where T is some type other
    than bool, then it obeys the identity &v[n] == &v[0] + n for all 0 <= n < v.size().

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

Sidebar

Related Questions

Possible Duplicate: std::vector<std::string> to char* array I have to call a c function that
Possible Duplicate: «F(5)» and «int x; F(x)» to call different functions? Can we overload
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: Can I comment a JSON file? We are using a .json file
Possible Duplicate: Call php function from javascript I understand that php is server side
Possible Duplicate: Pointer to local variable Can a local variable's memory be accessed outside
Possible Duplicate: Does std::list::remove method call destructor of each removed element? I have a
Possible Duplicate: How can I add a Trace() to every method call in C#?
Possible Duplicate: How can I call a new web page from javascript / jQuery
Possible Duplicate: FAQ : How to pass objects to functions in C++? Pointer vs.

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.