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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:19:14+00:00 2026-05-23T17:19:14+00:00

Create a UserArray of bit fields which can be declared as follows: The size

  • 0

Create a UserArray of bit fields which can be declared as follows: The size occupied by our Array will be less then a normal array. Suppose we want an ARRAY of 20 FLAGs (TRUE/FALSE). A bool FLAG[20] will take 20 bytes of memory, while UserArray<bool,bool,0,20> will take 4 bytes of memory.

  • Use class Template to create user array.
  • Use Bit wise operators to pack the array.
  • Equality operation should also be implemented.

    template<class T,int W,int L,int H>//i have used template<class T> 
                                       //but never used such way
    class UserArray{ 
            //....                 
    };        
    typedef UserArray<bool,4,0,20> MyType;
    

where:

  • T = type of an array element
  • W = width of an array element, 0 < W < 8
  • L = low bound of array index (preferably zero)
  • H = high bound of array index

A main program:

int main() {
      MyType Display;  //typedef UserArray<T,W,L,H> MyType; defined above

      Display[0] = FALSE; //need to understand that how can we write this?
      Display[1] = TRUE; //need to understand that how can we write this?

      //assert(Display[0]);//commented once, need to understand above code first
      //assert(Display[1]);//commented once..
      //cout << “Size of the Display” << sizeof(Display);//commented once..
}

My doubt is how those parameters i.e T,L,W & H are used in class UserArray and how can we write instance of UserArray as Display[0] & Display[1] what does it represent?

Short & simple example of similar type will be easy for me to understand.

  • 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-23T17:19:14+00:00Added an answer on May 23, 2026 at 5:19 pm

    W, L and H are non-type template parameters. You can instantiate a template (at compile-time) with constant values, e.g.:

    template <int N>
    class MyArray
    {
    public:
        float data[N];
    
        void print() { std::cout << "MyArray of size " << N << std::endl; }
    };
    
    MyArray<7> foo;
    MyArray<8> bar;
    
    foo.print();  // "MyArray of size 7"
    bar.print();  // "MyArray of size 8"
    

    In the example above, everywhere that N appears in the template definition, it will be replaced at compile-time by the supplied constant.

    Note that MyArray<7> and MyArray<8> are completely different types as far as the compile is concerned.

    I have no idea what the solution to your specific problem is. But your code won’t compile, currently, as you have not provided values for the template parameters.

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

Sidebar

Related Questions

Create an array class for Employee which will reserved 7 elements. The class will
I created a array using PHP $userarray = array('UserName'=>$username,'UserId'=>$userId,'UserPicURL'=>$userPicURL); How can I convert this
create table d(id numeric(1), code varchar(2)) After I create the above table how can
Create default iPad split view based apps from template from xcode 4, then we
create view Com as select C.id, IF(A.agree = null) THEN 0 else A.agree end
create unique index In DB2 UDB I can create an index using the following
create table person ( name varchar(15), attr1 varchar(15), attr2 varchar(1), attr3 char(1), attr4 int
Create a flat text file in c++ around 50 - 100 MB with the
Create a file called Valid[File].txt and stick some text in it. Start powershell and
Create Proc CrearNuevoAnuncio @Titulo varchar(250), @Precio int, @Descripcion varchar(250), @IDCategoria int, @IDImagen int, @Login

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.