user3290875
user3290875

Reputation: 13

C++ NetBeans error: expected unqualified-id before 'int'

I am new to c++ and I am getting errors and I am unsure why can anyone help me with this issue? thanks in advance.

Here is my header file.

#ifndef SSTACK_H
#define SSTACK_H

#include <cstdlib>
#include <string>

class sstack {
    public:
            // Constructor
            sstack( int cap);
            // Copy Constructor
            sstack( const sstack& s );
           ~sstack( );
            void push ( const std::string&  s);
            std::string& pop ();
            std::string&  top () const;
            bool IsEmpty () const;
            int size() const;
    int getCapacity() const;

    // NONMEMBER FUNCTIONS for the bag class
    // Precondition:  s1.size( ) + s2.size( ) <= s1.Capacity.
    // Postcondition: The stack returned is the union of s1 and s2.
    sstack operator +(const sstack& s2);

    private:
            int Capacity; // Capacity is the maximum number of items that a stack can hold
            std::string* DynamicStack; 
            int used; // How many items are stored in the stack
};

#endif

here is the .cpp file for the sstack MY ERRORS ARE IN THIS CLASS my first error is:

sstack.cpp:14:24: error: expected unqualified-id before 'int'

sstack.cpp:14:24: error: expected ')' before 'int'

and my second error is:

sstack.cpp:19:24: error: expected unqualified-id before 'const'

sstack.cpp:19:24: error: expected ')' before 'const' Ive looked around online and cant seem to figure out what the issue is any ideas?

btw like I said earlier I am new to c++ so if there is anything else that looks bad or wrong or can be done better please let me know so I can learn thank you

#include "sstack.h"




            // Constructor

            //ERROR HERE 
            sstack(int cap){

                test = new std::string [cap];

                Capacity = cap;
            }

            // Copy Constructor

               //ERROR 2 HERE
              sstack(const sstack& s){

                test = new std::string[1000];

                  for(int i = s.size()-1; i > 0; i--){
                        test[i] = *s.pop();
                    }//end of for

                 Capacity = s.getCapacity();
                 used = s.size();      
            }

            ~sstack(){
                delete []test;
            }

            void push ( const std::string&  s){
                test[used] = *s;
                used++;
            }

            std::string& pop (){
                used-= 1;
                popped =  test[used];
                test[used] = "";
              return *popped;

            }

            std::string&  top () const{
                top = test[used--];
                return *top;
            }

            bool IsEmpty () const{
                if(used <= 0){
                    return true;
                }else{
                    return false;
                }
            }

            int size() const{
                return used;
            }

    int getCapacity() const{
                return Capacity;
            }

    // NONMEMBER FUNCTIONS for the bag class
    // Precondition:  s1.size( ) + s2.size( ) <= s1.Capacity.
    // Postcondition: The stack returned is the union of s1 and s2.
    sstack operator +(const sstack& s2){
                int amount = used;
                if(amount + s2.size() <= Capacity){
                    for(int i = used + s2.size()-1; i > used; i--){
                        test[i] = *s2.pop();
                        used++;
                    }//end of for
                }//end of if
            }


            int Capacity = 1000; // Capacity is the maximum number of items that a stack can hold
            std::string* DynamicStack; 
            int used = 0; // How many items are stored in the stack
            std::string test[1000];
            std::string popped;
            std::string top;

Upvotes: 1

Views: 1696

Answers (1)

juanchopanza
juanchopanza

Reputation: 227518

You are missing the class scope in the member definitions:

sstack::sstack(int cap) { .... }
^^^^^^^^

void sstack::push ( const std::string&  s) { .... }
     ^^^^^^^^

Upvotes: 2

Related Questions