Attempting to integrate and exception header into a linked list..

My ide (xcode is complaining )
"Expected member name or ';' after declaration specifiers "
on the commented out "throw" lines in
ListP.h

Main
1
2
3
4
5
6
7
8
9
10
#include <iostream>

int main(int argc, const char * argv[])
{

    // insert code here...
    std::cout << "Hello, World!\n";
    return 0;
}


ListException.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifndef __lab1d__ListException__
#define __lab1d__ListException__

#include <iostream>
#include <stdexcept>
#include <string>

using namespace std;

class ListException : public logic_error
{

public:
    ListException(const string & message = " ")
    : logic_error(message.c_str())
    { }
};

#endif /* defined(__lab1d__ListException__) */ 


ListOutOfRangeException.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef __lab1d__ListOutOfRangeException__
#define __lab1d__ListOutOfRangeException__

#include <stdexcept>
#include <string>
#include <iostream>

using namespace std;

class ListOutOfRangeException : public out_of_range {

public:
    ListOutOfRangeException(const string & message = " ")
    : out_of_range(message.c_str())
    { }
                 };


ListP.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef __lab1d__ListP__
#define __lab1d__ListP__

#include <iostream>
#include "ListException.h"
#include "ListOutOfRangeException.h"

typedef char *ItemName;
typedef double ItemWeight;
typedef int qty_of_item;

class List {


public:
    // Constuctors and destuctor

    //** Default Constuctor */
    List();

    /** Copy Constuctor 
     * @parm aList  The list to copy. */
    List(const List& aList);

    /** Destuctor */
    ~List();

    // List Opertions
    bool isEmpty() const;
    int  getLenght() const;
    void insert(int index,
                    const ItemName& newItem,
                          ItemWeight& newItemWeight,
                          qty_of_item& newQtyOfItem );
       // throw(ListOutOfRangException, ListEception);
    void remove (int index);
       // throw(ListOutOfRangeException);


private:
    struct ListNode
    {
        ItemName item;
        ItemWeight Double;
        qty_of_item Qty;
        ListNode *next;
    };

    int size;
    ListNode *head;
    /** Locates a specified node in a liked list
     * @pre index is the number of the desired node
     * @post None.
     * @param index  The index of the node to locate
     * @return A pointer to the index-th node. if index < 1
     *      or index > the number of nodes in the list,
     *      retuns NULL. */

    ListNode *find(int index) const;

}; // end of list
    // end of header file

#endif /* defined(__lab1d__ListP__) */


I have not code the implementation file of ListP.h
yet. Not sure if that matters.


Some context: this is for homework (by no means is this the solution to my problem[I still have 2-3 other classes to write]), But I am following an linked pointer list ADT example out of "Data Abstraction and Problem Solving with C++: Walls and Mirrors (5th Edition) page 194"

any help would be great.
Last edited on
throw statements belong in functions.

If you're attempting to use a throw specifier, those were deprecated in C++11 and were a bad idea in C++03. However, if you must use them, get rid of the semi-colon immediately following the function declaration and before "throw".
Last edited on
Topic archived. No new replies allowed.