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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:52:37+00:00 2026-05-24T00:52:37+00:00

I want to write a class in C++ in which one of the parameter

  • 0

I want to write a class in C++ in which one of the parameter is a bitset<size>.
I want to give the facility to vary this “size” for any object of that class but should be constant for that object.

If I make a variable const int size; and initialize it in the constructor, then it does not compile because to writiting bitset<size> would require size to be static which would make it same for all objects of the class.

Is there any other method than making a class template and passing the size as classname<size>?

thanks but.. but this makes this Foo class objects whenever used as composition (object as data member)… would it be necessary to again make that class template. I made a class and Passed a (#define BIT_SIZE 16 to Foo bits;) it is giving compile errors undefined reference to Foo<16>::Foo(). where Foo() is the constructor. I thought it should work because that is also compile time. and i just wanted to make only size BIT_SIZE bits. should i make my “next level” class template ?? it can be that these errors were because of other mistakes. but i checked that again and again.


yes sir i have implemented that and but included the header files and not cpp files ………. when i changed these to cpp files … multiple declaration error came. i am working on linux ubuntu .. when i took these files to dev_cpp in windows that worked . may be because compiler did that automatically what i need to do. so what is that i need to do.

  • 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-24T00:52:38+00:00Added an answer on May 24, 2026 at 12:52 am

    No, there is no other method, because the code for actual instantiation for bitset<N> is generated at compile time, so you have no possibility to delay providing its size until runtime. You have to use the non-type template parameter.

    If it was possible, the creators of standard C++ library would have done this and it would be possible to provide the size for bitset at runtime, right?

    Using another bit set implementation is an option.

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

Sidebar

Related Questions

I want to write a simple class (PHP5) that can 'run' an unknown amount
As part of some WSGI middleware I want to write a python class that
Give a base class Base , I want to write a method Test, like
I wrote this n-array tree class. I want to write a method to add
I want to interrupt some specific grails domain class events(read,write,delete,update).Is there any hibernate eventlistner
I want to write class whose constructor takes two parameters, but the arguments are
I want to write a class with three int values in them and manipulate
Basically I want to write a class for parsing XML document for my iphone
I want to write in Delphi (2009 - so I have generic dictionary class)
In C# with MVC, i want to write a common utility or class in

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.