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

user3290875

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;
juanchopanza

You are missing the class scope in the member definitions:

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

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

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

From Dev

C++ Error "expected unqualified-id '(' token" before debugging

From Dev

error: expected unqualified-id before ‘const’

From Dev

error: expected unqualified-id before ‘const’

From Dev

error:expected unqualified-id before '=' token

From Dev

error: expected unqualified-id before 'while'|

From Dev

error: expected unqualified-id before ‘)’ token

From Dev

expected unqualified id before while c++

From Dev

error: expected unqualified-id on extern "C"

From Dev

expected unqualified id before "." token

From Dev

"error: expected unqualified-id before '.'" Compiling C++ App with OpenSSL Libraries

From Dev

c++ Class Header - "error: expected unqualified-id before ')' token"

From Dev

C++ Type alias error: expected unqualified-id before 'using'

From Dev

error: expected unqualified-id before ‘const’ on line 8

From Dev

Compile error for QT 5.2.1; expected unqualified-id before 'delete'

From Dev

Getting error: expected unqualified-id before 'default'

From Dev

error: expected unqualified-id before ‘const’ on line 8

From Dev

Compile error for QT 5.2.1; expected unqualified-id before 'delete'

From Dev

Unusual error: expected unqualified-id before ‘delete’/expected initializer before ‘delete’

From Dev

C and C++ : data file with error "Expected unqualified-id"

From Dev

expected unqualified-id error with class in C++?

From Dev

Objective-C++ Error: Expected unqualified-id

From Dev

What is "expected unqualified-id" error in C++?

From Dev

Expected unqualified-id before 'xor' token

From Dev

Expected unqualified-id before '[' token

From Dev

expected unqualified-id before QDir directory

From Dev

Expected Unqualified-Id before 'delete' function

From Dev

Expected unqualified-id before ‘nullptr’

From Dev

Expected unqualified-id before 'char'

Related Related

  1. 1

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

  2. 2

    C++ Error "expected unqualified-id '(' token" before debugging

  3. 3

    error: expected unqualified-id before ‘const’

  4. 4

    error: expected unqualified-id before ‘const’

  5. 5

    error:expected unqualified-id before '=' token

  6. 6

    error: expected unqualified-id before 'while'|

  7. 7

    error: expected unqualified-id before ‘)’ token

  8. 8

    expected unqualified id before while c++

  9. 9

    error: expected unqualified-id on extern "C"

  10. 10

    expected unqualified id before "." token

  11. 11

    "error: expected unqualified-id before '.'" Compiling C++ App with OpenSSL Libraries

  12. 12

    c++ Class Header - "error: expected unqualified-id before ')' token"

  13. 13

    C++ Type alias error: expected unqualified-id before 'using'

  14. 14

    error: expected unqualified-id before ‘const’ on line 8

  15. 15

    Compile error for QT 5.2.1; expected unqualified-id before 'delete'

  16. 16

    Getting error: expected unqualified-id before 'default'

  17. 17

    error: expected unqualified-id before ‘const’ on line 8

  18. 18

    Compile error for QT 5.2.1; expected unqualified-id before 'delete'

  19. 19

    Unusual error: expected unqualified-id before ‘delete’/expected initializer before ‘delete’

  20. 20

    C and C++ : data file with error "Expected unqualified-id"

  21. 21

    expected unqualified-id error with class in C++?

  22. 22

    Objective-C++ Error: Expected unqualified-id

  23. 23

    What is "expected unqualified-id" error in C++?

  24. 24

    Expected unqualified-id before 'xor' token

  25. 25

    Expected unqualified-id before '[' token

  26. 26

    expected unqualified-id before QDir directory

  27. 27

    Expected Unqualified-Id before 'delete' function

  28. 28

    Expected unqualified-id before ‘nullptr’

  29. 29

    Expected unqualified-id before 'char'

HotTag

Archive