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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:21:54+00:00 2026-05-30T04:21:54+00:00

I have a C++ class with vector<float> members which are initialized in the constructor

  • 0

I have a C++ class with vector<float> members which are initialized in the constructor to a size determined by one of the constructor’s arguments.

summingBuffer = vector<float>(requiredSize);

How do I check whether the vector constructor has successfully allocated the the required space? The instance vars aren’t pointers (should they be?) so if (NULL==myVector) doesn’t work. Does vector throw an exception on allocation error? How about checking .size() afterwards?

Thank you…

  • 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-30T04:21:55+00:00Added an answer on May 30, 2026 at 4:21 am

    The vector constructor will raise bad_alloc if it couldn’t allocate enough storage, no need for extra checks.

    Using pointers is not a good idea if you don’t absolutely need them.

    Also, looks like you could initialize your vectors directly rather than how you’re doing it by using your constructor’s initializer list. Something like:

    struct foo {
      std::vector<float> things;
    
      foo(int vsize) : things(vsize) {
        // rest of constructor code
      }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering something. I have class Polygon , which composes a vector of Line
I have a class which has a private attribute vector rectVec; class A {
I have a class called Object : class Object { public: Vector pos; float
Suppose I have a class: public class Vector { public float X { get;
I have a vector class with a properly overloaded Vect*float operator and am trying
Say I have: class Vector3 { float x, y, z; ... bunch of cuntions
I have class A: public B { ...} vector<A*> v; I want to do
I have a class with a vector of pointers to objects. I've introduced some
I have a class class ChartLine{ protected: vector<Point> line; // points connecting the line
I have a class that has a vector of another class objects as 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.