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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:14:14+00:00 2026-06-12T18:14:14+00:00

I am learning how to make a template class and I follow the concept

  • 0

I am learning how to make a template class and I follow the concept but am running into an error. I have a class that I turned into a template but I get the following errors;

simplestack.h(24): error C2955: ‘SimpleStack’ : use of class template requires template argument list

simplestack.h(9) : see declaration of ‘SimpleStack’

simplestack.h(28): error C2244: ‘SimpleStack::push’ : unable to match function definition to an existing declaration

simplestack.h(12) : see declaration of ‘SimpleStack::push’

This is my code:

const int MAX_SIZE = 100; 
template <typename T>
class SimpleStack
{
public:
  SimpleStack();
  SimpleStack & push(T value);
  T pop();

private:
  T items[MAX_SIZE];
  T top;
};
template <typename T>
SimpleStack<T>::SimpleStack() : top(-1)
{}

template <typename T>
SimpleStack &SimpleStack<T>::push(T value)
{
  items[++top] = value;
  return *this;
}

template <typename T>
T SimpleStack<T>::pop()
{
  return items[top--];
}

Note: every time I try to chance MAX_SIZE to T it won’t accept it. Thank you for any help.

  • 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-12T18:14:16+00:00Added an answer on June 12, 2026 at 6:14 pm

    The method push should return SimpleStack<T>&, not SimpleStack&.

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

Sidebar

Related Questions

I have a template class, what I want to do are the following Make
I am still learning to make a Joomla component, but I have run into
I have a small RIA that I built as a learning/make-my-life-easier project that uses
I'm just learning codeigniter, and I seem to have run into something that is
I have a quick question. I am learning how to make a registration form
I'm learning and trying to make a site but I'm a bit confused about
I'm a student learning PHP. I basically make the stuff work, but never wondered
I have a task at work that involves converting legacy SGM files into XML.
I'm just learning MVC and have a question that I'm sure is obvious to
I'm learning to make AJAX calls with jQuery and rendering the data with template

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.