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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:28:47+00:00 2026-05-12T19:28:47+00:00

Consider one has some user defined types, and containers of those types that are

  • 0

Consider one has some user defined types, and containers of those types that are often manipulated because there are often multiple instances of those types on screen at a time.

Currently I have a header with an associated source file and a namespace to hold these containers, but should I create a separate class to hold them? Should I put the containers in the same header file as the class that they contain (but obviously outside the class)? What is the standard practice for situations like this?

  • 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-12T19:28:47+00:00Added an answer on May 12, 2026 at 7:28 pm

    I once typedef’d them whenever a specific class has the container as part of that class’s interface. Then anyone who needed to use that class easily figured out that a “FooVec” is a std::vector of Foo without a lot of fus.

    However, this is an imperfect solution, consider the following code:

    namespace bar
    {
    
      typedef std::vector<Foo> FooVec;
    
      class CClass
      {
          CClass(FooVec&)
          {
              ...
          }
      };
    }
    

    Naturally the problem comes in when your colleague redefines FooVec for their class:

    namespace bar
    {
    
    typedef std::vector<const Foo> FooVec;
    
    class CAnotherClass
    {
        CAnotherClass(FooVec&)
        {
            ...
        }
    }
    
    };
    

    The simplest thing I’ve found to solve this is to have them in roughly one common include per namespace/library/group of associated classes. So when someone else adds a typedef to something in the bar namespace, you can have them all in one place. IE:

     barTypes.h
    
     namespace bar
     {
             typedef std::vector<Foo> FooVec;
             typedef std::vector<const Foo> FooConstVec;
    
     }
    

    By keeping it to one header per small set of classes (ie per namespace) you don’t get a gigantic file full of typedefs. It still gives your users good visibility into the types that are a part of your class’s interface. Once this header is established, its just a matter of maintaining discipline on your team to use it instead of establishing additional typedefs.

    May also wish to have this header as part of a precompiled header if you’re anal about build performance.

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

Sidebar

Related Questions

Consider the following, I have a Job class that has inputs and one output.
Consider the following scenario: a user has one or more (bank) accounts. The the
So I don't consider myself a novice at MySQL but this one has me
Consider a table products which has product details including its category. One product may
Consider three tables: one of items, one of tags on those items, and the
Consider that I have 1 resource and 2 urls (let's say new one and
This is something that has been pulling at me for a while. Consider a
How does one implement a HUD mirror? To simplify the problem let's consider that
Consider this case: public Class1 { public static final String ONE = ABC; public
Consider the case of blogspot.com the domain is the one blogspot.com only but suppose

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.