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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:18:47+00:00 2026-06-16T00:18:47+00:00

From what I understand, if you have, for example, an std::vector<int> and an std::vector<float>

  • 0

From what I understand, if you have, for example, an std::vector<int> and an std::vector<float>, the compiler creates two classes, one for each type. Thus, although you reduce the amount of code written, you do not reduce executable size (correct me if I’m wrong).

Is the same true even if the type is a pointer? For example, would instantiating an std::vector<SomeClass*> and an std::vector<SomeOtherClass*> necessarily cause the compiler to generate separate code for each of the two instantiations?

  • 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-16T00:18:48+00:00Added an answer on June 16, 2026 at 12:18 am

    The compiler instantiates as many classes from the template as your program uses. Code generated to go in your executable is a slightly different matter, though, from what classes exist in your program.

    In practice, most operations on vector will be inlined. So the executable size probably doesn’t change very much according to how many different classes are instantiated from that template because the bulk of the code size is per function call site rather than per distinct class. But as far as it does depend on the number of instantiations, vector<SomeClass*> and vector<SomeOtherClass*> are different classes.

    If you do an explicit instantiation of vector, then all the member functions will get generated for the class. You’ll probably see that difference in code size, if you look for it. But normally you don’t explicitly instantiate template classes, and so only the member functions you use are generated.

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

Sidebar

Related Questions

I have looked here and from what I understand the following regex simply means
I have read about session fixation and from what I understand it forces a
I have read the document Authentication (official from Facebook). I still don't understand the
From what I understand IMAP requires a connection per each user. I'm writing an
Greetings, Any input on a way to divide a std::vector into two equal parts
I have written some C++ code that generates a std::vector. I also have a
I have two libraries, one of which depends on the other. The first library
I have two vector objects that contain different types of data that are ordered
Many classes in the c++ standard library now have move constructors, for example -
Hi i have this command pattern example from the web , but there is

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.