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 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

This question requires some hypothetical background. Let's consider an employee table that has columns
This is something that has been pulling at me for a while. Consider a
Suppose I have a list of type list<boost::any> that has some type in it
Out of the following queries, which method would you consider the better one? What
Consider type like this one public interface IHaveGenericMethod { T1 Method<T1>(T1 parm); T2 Method<T1,T2>(T1
This question is a bit rhetorical. At some point i got a feeling that
Consider a typical social networking website, which has more or less the following models:
I have a csv file into which has crept some ^M dos line ends,
I have a class myclass that has a private member param_map class some_class {
I have some code that sorts table columns by object properties. It occurred to

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.