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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:25:56+00:00 2026-06-18T06:25:56+00:00

I have a list as a private member of a class that has two

  • 0

I have a list as a private member of a class that has two template arguments: type for the data type of the list elements and size for the number of elements in the list. To this end, I want to use the list’s fill constructor using my two template arguments. Here is my attempt:

#include <list>

template <typename type, unsigned int size>
class my_class {

   private:
      std::list<type> my_queue(size, 0);

   // More code here...

};

My approach seems to follow the information and example provided here; but when I compile this, I get the following error.

error: 'size' is not a type
error: expected identifier before numeric constant
error: expected ',' or '...' before numeric constant

It seems as though it recognizes the declaration of the list by its default constructor instead of the fill constructor. Can anyone help me solve this?

Thank you!

Edit: here is my revised source with more detail. I am now having trouble with the public method. Note: this is my class’s header file.

#include <list>

template <typename T, unsigned int N>
class my_class {

   private:

      std::list<T> my_queue;

   public:

      // Constructor
      my_class() : my_queue(N, 0) { }

      // Method
      T some_function(T some_input);
      // The source for this function exists in another file.

};

Edit 2: Final implementation… thank you, @billz!

#include <list>

template <typename T, unsigned int N>
class my_class {

   private:

      std::list<T> my_queue;

   public:

      // Constructor
      my_class() : my_queue(N, 0) { }

      // Method
      T some_function(T some_input){
         // Code here, which accesses my_queue
      }

};
  • 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-18T06:25:57+00:00Added an answer on June 18, 2026 at 6:25 am

    You could only initialize member variable in constructor before C++11, better use uppercase character as template argument:

    template <typename T, unsigned int N>
    class my_class {
       public:
        my_class() : my_queue(N, 0) { }
    
       private:
          std::list<T> my_queue;
    
       // More code here...
    
    };
    

    Edit:

    T some_function(T some_input); C++ only supports inclusive-module, you need to define some_function in the same file as my_class is declared.

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

Sidebar

Related Questions

I have two classes, A and B Class B has a private member variable
I have class A that has some primitive attributes and also member of type
I have a Poly3D class in C++, which has a sole member: list<Point_3> using
i have a member like this in a serializable class: private final Map<String, List<T>>
I have the following class structure class Top : NotifyPropertyChanged { private List<Inner> innerList;
I have a List<MyClass> The class is like this: private class MyClass { public
I have an SQLiteOpenHelper class that implements the singleton pattern and has three methods:
I have a class with a static std::map member variable that maps char s
I have a user defined class that I want to create a public List
In .Net/C# I have a class that's derived from List. When I try 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.