Linked Set Implementation

I'm trying to Implement a LinkedSet and will then read in files to make a function that spell checks another file that the user inputs. I'm having a problem instantiating all of my functions that I will need in my LinkedSet.

I'm getting the error code:
In function ‘int main()’:
.../projects/project3/LinkedSetTester.cpp:138:26: error: cannot declare variable ‘Set’ to be of abstract type ‘LinkedSet<std::__cxx11::basic_string<char> >’
LinkedSet<std::string> Set;

Along with some other notes.
I know it is because I have it declared as a virtual method and something with my arguments must be off, I just can't seem to find out where! Any help would be greatly appreciated.
Thanks,
Beez


Set Interface File
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef _SET_INTERFACE
#define _SET_INTERFACE

#include <vector>
using namespace std;
/** @class SetInterface SetInterface.h "SetInterface.h"
 *
 *  Definition of SetInterface class template. */
template <typename ItemType>
class SetInterface {
 public:

  /** Virtual destructor. */
  virtual ~SetInterface() {}

  /** Gets the current number of entries in this set.
   *
   *  @return The integer number of entries currently in the set. */
  virtual int size() const = 0;

  /** Sees whether this set is empty.
   *
   *  @return True if the set is empty, or false if not. */
  virtual bool isEmpty() const = 0;

  /** Gets the maximum number of items allowed in a set
   *  @return The integer number of maximum items allowed in a set
   */
  virtual int getCapacity() const = 0;

  /** Sets the maximum number of items allowed in a set
   *  @post The capacity member of the Set instance will be set to
   *        whatever number was passed in
   *  @param num The maximum number of items that can be stored in a set
   */
  virtual void setCapacity(int) = 0;

  /** Counts the number of times a given entry appears in set.
   *
   *  @param anEntry The value of the entry to be counted.
   *
   *  @return The number of times anEntry appears in this set.
   */
  virtual int count(const ItemType&) const = 0;

  /** Adds a new entry to this set.
   *
   *  @post If successful, newEntry is stored in the set and the
   *        count of items in the set has increased by 1.
   *
   *  @param newEntry The object to be added as a new entry.
   *
   *  @return True if addition was successful, or false if not. */
  virtual bool add(const ItemType&) = 0;

  /** Removes one occurrence of a given entry from this set, if
   *  possible.
   *
   *  @post If successful, anEntry has been removed from the set and
   *        the count of items in the set has decreased by 1.
   *
   *  @param anEntry The value of the entry to be removed.
   *
   *  @return True if removal was successful, or false if not. */
  virtual bool remove(const ItemType& ) = 0;

  /** Removes all entries from this set.
   *
   *  @post This set contains no items (thus the count is 0). */
  virtual void clear() = 0;


  /** Tests whether this set contains a given entry.
   *
   *  @param anEntry The value of the entry to locate.
   *
   *  @return True if this set contains anEntry, or false
   *          otherwise. */
  virtual bool contains(const ItemType& ) const = 0;

  /** Converts this set into a vector.
   *
   *  @return A vector containing all the entries in this set. */
  virtual vector<ItemType> toVector() const = 0;
};
#endif

Linked Set Header File
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 LINKED_BAG_
#define LINKED_BAG_

#include <vector>

#include "setInterface.h"
#include "Node.h"

/** @class LinkedBag LinkedBag.h "LinkedBag.h"
 *
 *  Specification of a pointer-based ADT bag. */
template <typename ItemType>
class LinkedSet : public SetInterface<ItemType> {
 private:
  /** Pointer to first node. */
  Node<ItemType>* headPtr = nullptr;

  /** Number of items in this bag. */
  int itemCount = 0;

  /** Gets a pointer to the node containing the target in this bag.
   *
   * @pre None.
   *
   * @post None.
   *
   * @param target The ItemType value to find.
   *
   * @return A pointer to the node that contains the given target or
   *         nullptr if the bag does not contain the target. */
  Node<ItemType>* getPointerTo(const ItemType& target) const;

 public:
  /** Default constructor. */
  LinkedSet() = default;

  /** Copy constructor. */
  LinkedSet(const LinkedSet<ItemType>& Set);

  virtual ~LinkedSet();

  virtual int getCurrentSize() const;

  virtual bool isEmpty() const;

  virtual bool add(const ItemType& newEntry);

  virtual bool remove(const ItemType& anEntry);

  virtual void clear();

  virtual int getFrequencyOf(const ItemType& anEntry) const;

  virtual bool contains(const ItemType& anEntry) const;

  //  virtual LinkedSet<ItemType> difference(LinkedSet<ItemType>&) const;

  virtual std::vector<ItemType> toVector() const;
};

#include "LinkedSet.cpp"

#endif

Linked Set Driver File
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
  
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#include "LinkedSet.h"

void displaySet(LinkedSet<std::stringx>& Set) {

  cout << "The set contains "
       << Set.getCurrentSize()
       << " items:"
       << endl;

  std::vector<std::string> setItems = Set.toVector();

  int numberOfEntries = (int)setItems.size();

  for (int i(0); i < numberOfEntries; ++i) {
    cout << setItems[i]
         << " ";
  }

  cout << endl
       << endl;
}

void setTester(LinkedSet<std::string>& Set) {

  cout << "isEmpty: returns "
       << Set.isEmpty()
       << "; should be 1 (true)"
       << endl;

  displaySet(Set);

  std::string items[] = {"one", "two", "three", "four", "five", "one"};

  cout << "Add 6 items to the set: "
       << endl;

  for (int i(0); i < 6; ++i) {
    Set.add(items[i]);
  }

  displaySet(Set);

  cout << "isEmpty(): returns "
       << Set.isEmpty()
       << "; should be 0 (false)"
       << endl;

  cout << "getCurrentSize(): returns "
       << Set.getCurrentSize()
       << "; should be 6"
       << endl;

  cout << "Try to add another entry: add(\"extra\") returns "
       << Set.add("extra")
       << "; should be 0 (false)"
       << endl;

  cout << "contains(\"three\"): returns "
       << Set.contains("three")
       << "; should be 1 (true)"
       << endl;

  cout << "contains(\"ten\"): returns "
       << Set.contains("ten")
       << "; should be 0 (false)"
       << endl;

  cout << "getFrequencyOf(\"one\"): returns "
       << Set.getFrequencyOf("one")
       << "; should be 2"
       << endl;

  cout << "remove(\"one\"): returns "
       << Set.remove("one")
       << "; should be 1 (true)"
       << endl;

  cout << "getFrequencyOf(\"one\"): returns "
       << Set.getFrequencyOf("one")
       << "; should be 1"
       << endl;

  cout << "remove(\"one\"): returns "
       << Set.remove("one")
       << "; should be 1 (true)"
       << endl;

  cout << "remove(\"one\"): returns "
       << Set.remove("one")
       << "; should be 0 (false)"
       << endl;

  cout << "getFrequencyOf(\"one\"): returns "
       << Set.getFrequencyOf("one")
       << "; should be 0"
       << endl;

  cout << endl;

  displaySet(Set);

  cout << "After clearing the bag, ";

  Set.clear();

  cout << "isEmpty(): returns "
       << Set.isEmpty()
       << "; should be 1 (true)"
       << endl;
}

int main() {

  LinkedSet<std::string> Set;

  cout << "Testing the Array-Based Bag:"
       << endl
       << "The initial bag is empty."
       << endl;

  setTester(Set);

  cout << "All done!"
       << endl;

  return EXIT_SUCCESS;
}
Gotta implement all polymorphic methods: virtual int size() const = 0;
I did that, however I'm still getting the 'cannot declare variable "Set" to be of abstract type error.
Might be a bit late but purely abstract classes can only be used as a pointer for another non-abstract type.

Topic archived. No new replies allowed.