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

  • Home
  • SEARCH
  • 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 6643545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:03:46+00:00 2026-05-26T00:03:46+00:00

I just started learning C++ and have a question about vectors. The book I’m

  • 0

I just started learning C++ and have a question about vectors.
The book I’m reading states that if I want to extract the size of a vector of type double (for example), I should do something like:

vector<double>::size_type vector_size;
vector_size = myVector.size();

Whereas in Java I might do

int vector_size;
vector_size = myVector.size();

My question is, why is there a type named vector::size_type? Why doesn’t C++ just use int?

  • 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-26T00:03:47+00:00Added an answer on May 26, 2026 at 12:03 am

    C++ is a language for library writing*, and allowing the author to be as general as possible is one of its key strengths. Rather than prescribing the standard containers to use any particular data type, the more general approach is to decree that each container expose a size_type member type. This allows for greater flexibility and genericity. For example, consider this generic code:

    template <template <typename...> Container, typename T>
    void doStuff(const Container<T> & c)
    {
      typename Container<T>::size_type n = c.size();
      // ...
    }
    

    This code will work on any container template (that can be instantiated with a single argument), and we don’t impose any unnecessary restrictions on the user of our code.

    (In practice, most size types will resolve to std::size_t, which in turn is an unsigned type, usually unsigned int or unsigned long — but why should we have to know that?)

    *) I’m not sure what the corresponding statement for Java would be.

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

Sidebar

Related Questions

I have just started learning C# and would have one question that I cannot
I just recently started learning Java. I have a question which is more about
Just started learning x64 assembly and I have a question about functions, arguments, and
I just started learning about database normalization and I have a question about one
I have just started learning GWT. My question is pretty simple: If I create
I just started learning Objective-C and OOP ... so I have very stupid question
I just started learning about ASP.NET, and I have a couple of questions. Am
Very confused over this. I've just started learning about pointers and have now decided
We just started learning about class inheritance and attribute lookup in python. I have
I have just started learning Erlang and am trying out some Project Euler problems

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.