Language: C++

#include <cstdlib>
#include <iostream>
#include <string>

// ---Fixed-length Stuck with template---
// Covers user-defined type
// Instantiating as following:
// Stack<TYPENAME> VARIABLENAME(SIZE);

template <class T>
class Stack{ 
public:
    // Constructor, which is given stack size
    Stack( int max_size ){
        size = max_size;
        initial = top = new T[size];
    }

    // Check whether data are being stucked or empty
    bool IsEmpty(){ 
        return top == initial;
    }
    // Check whether data are full or not
    bool IsFull(){
        return top == initial + size - 1;
    }
    // Returns size
    int GetSize(){
        return size;
    }

    // Returns number of stucked data
    int GetNumOfData(){
        int num = 0;
        for( auto itr = initial+1; itr <= top; ++itr ){
            ++num;
        }
        return num;
    }

    // Add a T-type element to the top of stuck
    void Push( T x ){
        if( IsFull() ){
            std::cerr << "Stack Overflow! the pushed data was dumped\n"
        }else{
            ++top;
            *top = x;
        }
    }

    // Take an element out from the top of stuck
    T Pop(){
        if( IsEmpty() ){
            std::cerr << "Stack Underflow!\n";
        }else{
            --top;
        }
        return *(top + 1);
    }

    // Print NumOfElems and all elements out from top to base
    void Print(){
        std::cout << "Number of elements: [" << GetRest() << "]\n";
        std::cout << *top << " <- top\n";
        for( auto itr = top - 1; itr >= initial + 2; --itr ){
            std::cout <<  *itr << "\n";
        }
        std::cout << *( initial + 1 ) << "\n";
    }

private:
    T* top;
    T* initial;
    int size;
};

// Calculation two numbers by an operator
// ex: "CalcByOperator<int>( 2, 3, '*' )"
//     returns 6, which is result of "2 * 3"
template <typename T>
T CalcByOperator(T a, T b, char oprtr){
    switch(oprtr){
        case '+':
            return a + b;
        case '-':
            return a - b;
        case '*':
            return a * b;                
        default:
            std::cerr << "Input Error\n";
            std::exit(0);
    }

}


//
int main(){
    Stack<int> stack;
    std::string str;
    int tmp;
    const char* input;

    while( std::cin >> str ){
        input = str.c_str();
        if( *input == '+' || *input == '-' || *input == '*' ){
            stack.Push( CalcByOperator<int>( stack.Pop(), stack.Pop(), char(*input) ) );
        }else{
            stack.Push( std::atoi(input) );
        }
        //stack.Print();
    }

    while( stack.GetRest() > 1 ){
        stack.Push( CalcByOperator<int>( stack.Pop(), stack.Pop(), '+' ) );
    }

    std::cout << stack.Pop() << "\n";
}


Compiler output:
a.cc: In member function 'void Stack<T>::Push(T)':
a.cc:45:9: error: expected ';' before '}' token
   45 |         }else{
      |         ^
a.cc: In member function 'void Stack<T>::Print()':
a.cc:63:49: error: there are no arguments to 'GetRest' that depend on a template parameter, so a declaration of 'GetRest' must be available [-fpermissive]
   63 |         std::cout << "Number of elements: [" << GetRest() << "]\n";
      |                                                 ^~~~~~~
a.cc:63:49: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
a.cc: In function 'int main()':
a.cc:99:16: error: no matching function for call to 'Stack<int>::Stack()'
   99 |     Stack<int> stack;
      |                ^~~~~
a.cc:14:5: note: candidate: 'Stack<T>::Stack(int) [with T = int]'
   14 |     Stack( int max_size ){
      |     ^~~~~
a.cc:14:5: note:   candidate expects 1 argument, 0 provided
a.cc:11:7: note: candidate: 'constexpr Stack<int>::Stack(const Stack<int>&)'
   11 | class Stack{
      |       ^~~~~
a.cc:11:7: note:   candidate expects 1 argument, 0 provided
a.cc:11:7: note: candidate: 'constexpr Stack<int>::Stack(Stack<int>&&)'
a.cc:11:7: note:   candidate expects 1 argument, 0 provided
a.cc:114:18: error: 'class Stack<int>' has no member named 'GetRest'
  114 |     while( stack.GetRest() > 1 ){
      |                  ^~~~~~~