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

  • Home
  • SEARCH
  • 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 7744877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:52:26+00:00 2026-06-01T09:52:26+00:00

I am doing some exercises and tried to convert a simple class into a

  • 0

I am doing some exercises and tried to convert a simple class into a template class.
After changing the code I wound up with a bunch of linker errors and so I removed the header file inclusion statement from the implementation and now include the implementation file at the bottom of the header file. Ever since then I get this strange syntax error: missing ‘;’ before ‘<‘. I can’t see what I am doing wrong.

This is my header file:

#ifndef STACK_H
#define STACK_H

#include <iostream>

template<class T>
class Stack
{
    T* buffer;
size_t count;
public:
Stack();
~Stack();
void push(T value);
void pop();
T top() const;
size_t size() const;
};

#include "Stack.cpp"

#endif

And this is the implementation file:

template<class T>
Stack<T>::Stack() : count(0)
{
buffer = new T;
}

template<class T>
Stack<T>::~Stack()
{
delete[] buffer;
}

template<class T>
void Stack<T>::push( T value )
{
if(size() == 0) *(buffer) = value;
else
{
    T* newBuffer = new T[count+1];

    for(size_t i=0; i <= size(); ++i)
        newBuffer[i] = buffer[i];

    newBuffer[count] = value;
    buffer = newBuffer;
}
++count;
}

template<class T>
void Stack<T>::pop()
{
if(size() <= 0) return;

 buffer[size()-1]=0;
 --count;
}
template<class T> 
typename T Stack<T>::top() const
{
if(size() <= 0) 
{
std::cout << "the stack is empty" << std::endl;
return -1;
}
else
{
    return buffer[size()-1];
}
}

template<class T>
size_t Stack<T>::size() const
{
return count;
}

Any help would be 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-06-01T09:52:27+00:00Added an answer on June 1, 2026 at 9:52 am

    My guess is that you’re attempting to compile the .cpp file. Despite the confusing file extension, it isn’t a complete translation unit, so it can’t be compiled by itself. Just include the header from any file that uses the class.

    Personally, I’d move the implementation into the header file; others might give it a different file extension that doesn’t look like a compilable source file (I’ve seen .tcc and .inl used for such files, but there’s no universal convention).

    Also:

    template<class T> 
    typename T Stack<T>::top() const
    ^^^^^^^^^
    

    Remove that typename; you only put that before a type name that depends on a template parameter.

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

Sidebar

Related Questions

I'm just doing some University related Diffie-Hellman exercises and tried to use ruby for
Doing some exercises with simple file encryption/decryption and am currently just reading in a
So I was doing some simple C++ exercises and I noticed an interesting feat.
I'm doing some SOAP exercises based on this example: http://www.vankouteren.eu/blog/2009/03/simple-php-soap-example/ But, I cannot get
I'm doing some Project Euler exercises and I've run into a scenario where I
I am doing some exercises in my object-oriented javascript book, I notice that this:
I am doing some exercises in assembly language and I found a question about
I`m doing some web.config modifications with SPWebConfigModification class. When adding them to WebApplication and
After doing some research on the subject, I've been experimenting a lot with patterns
I've been doing some exercises from a book and I'm wondering if you could

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.