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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:26:48+00:00 2026-05-21T10:26:48+00:00

Hya, Can anyone please tell me how this thing is working? template <typename T,

  • 0

Hya,

Can anyone please tell me how this thing is working?

template <typename T,
template <typename ELEM> class CONT = std::deque >
class Stack {
private:
CONT<T> elems; // elements

public:
void push(T const&); // push element
void pop(); // pop element
T top() const; // return top element
bool empty() const { // return whether the stack is empty
return elems.empty();
}
};

What i don’t understand is this :
template class V or say this “template class CONT = std::deque”

i visualize this as

template <class>
class CONT = std::deque // here CONT is templatized class declaration.

but what pesters me is , how can we assign something to class name CONT , rather than writing its definition (which i’ve done till this time):

template <class>
class CONT{
//def
}

one more thing :

template <class> // why its only class written in angle bracket there should be also be name
like : template<class ty>

Thanks a lot , any help is very appreciated)

  • 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-21T10:26:48+00:00Added an answer on May 21, 2026 at 10:26 am

    What i don’t understand is this : template class V

    There is no such line in your question, so I can’t help with that.

    template< template <typename ELEM> class CONT = std::deque >
    class Stack
    

    This is a declaration of a template template parameter. You pass a template into the Stack template, and then Stack can use it internally.

    The = std::deque part is a default value, in case you leave the CONT parameter unspecified. (std::deque is a predefined template.)

    However, this will not work, because std::deque takes two arguments. This will work:

    template< template <typename ELEM, typename ALLOC> class CONT = std::deque >
    class Stack
    

    However ELEM and ALLOC do not actually name anything; they exist merely to clarify what the parameter list of the required template is. So, you can omit them:

    template< template <typename, typename> class CONT = std::deque >
    class Stack
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a fraction class for a school project, and my brain is
Hya advance users of SO, First of all I am new to C++, so
Hya, I would like to run a bit of code only if the focused

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.