Need help with assignment

Pages: 12
Continued:

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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
  list.Sort();
  Test(list.ToString() == "StRiNg #1, sTrInG #10, StRiNg #11, sTrInG #12, StRiN"
      "g #13, sTrInG #14, StRiNg #15, sTrInG #16, StRiNg #17, sTrInG #18, StRiN"
      "g #19, sTrInG #2, sTrInG #20, StRiNg #21, sTrInG #22, StRiNg #23, sTrInG"
      " #24, StRiNg #25, sTrInG #26, StRiNg #27, sTrInG #28, StRiNg #29, StRiNg"
      " #3, sTrInG #30, StRiNg #31, sTrInG #4, StRiNg #5, sTrInG #6, StRiNg #7,"
      " sTrInG #8, StRiNg #9",
       "Sort() && ToString()");
  cout << "Testing Overloaded <<:\n" << list << endl;

  cout << "\n*****Member Functions with 1000 Items*****\n";
  for (int i = 0; i < 969; i++)
    list.AddFront(new string("A"));
  Test(list.GetSize() == 1000, "AddFront(Adding 969 More Items) / GetSize()");
  Test(list.GetCapacity() == 1000, "GetCapacity()");

  cout << "\n*****Clearing All Items*****\n";
  list.Clear();
  Test(list.GetSize() == 0, "Clear() && GetSize()");
  Test(list.GetCapacity() == 1000, "GetCapacity()");
  Test(list.ToString() == "", "ToString()");
  Test(list.Empty() == true, "Empty()");

  try {
    list.At(0);
  } catch (const string &e) {
    Test(e == "Invalid Location", "At(0) EXCEPTION HANDLING");
  }

  try {
    list.GetFirst();
  } catch (const string &e) {
    Test(e == "Array Empty", "GetFirst() EXCEPTION HANDLING");
  }

  try {
    list.GetLast();
  } catch (const string &e) {
    Test(e == "Array Empty", "GetLast() EXCEPTION HANDLING");
  }

  try {
    list.DeleteFront();
  } catch (const string &e) {
    Test(e == "Array Empty", "DeleteFront() EXCEPTION HANDLING");
  }

  try {
    list.DeleteBack();
  } catch (const string &e) {
    Test(e == "Array Empty", "DeleteBack() EXCEPTION HANDLING");
  }

  cout << "\n*****Member Functions with 1 Item*****\n";
  list.AddFront(new string("Hello"));
  Test(list.GetSize() == 1, "AddFront(\"Hello\") && GetSize()");
  Test(list.GetCapacity() == 1000, "GetCapacity()");
  Test(list.ToString() == "Hello", "ToString()");
  Test(list.Empty() == false, "Empty()");
  try {
    list.At(1);
  } catch (const string &e) {
    Test(e == "Invalid Location", "At(1) EXCEPTION HANDLING");
  }
  Test(*list.At(0) == "Hello", "At(0)");
  Test(*list.GetFirst() == "Hello", "GetFirst()");
  Test(*list.GetLast() == "Hello", "GetLast()");
  cout << "Testing Overloaded <<:\n" << list << endl;

  // Tests
  cout << "\n*****Overloaded Constructor*****\n";
  DynamicStringArray list2(0);
  Test(list2.GetSize() == 0, "DynamicStringArray(0) && GetSize()");
  Test(list2.GetCapacity() == 10, "GetCapacity()");
  Test(list2.ToString() == "", "ToString()");
  Test(list2.Empty() == true, "Empty()");

  try {
    list2.At(0);
  } catch (const string &e) {
    Test(e == "Invalid Location", "At(0) EXCEPTION HANDLING");
  }

  try {
    list2.GetFirst();
  } catch (const string &e) {
    Test(e == "Array Empty", "GetFirst() EXCEPTION HANDLING");
  }

  try {
    list2.GetLast();
  } catch (const string &e) {
    Test(e == "Array Empty", "GetLast() EXCEPTION HANDLING");
  }

  try {
    list2.DeleteFront();
  } catch (const string &e) {
    Test(e == "Array Empty", "DeleteFront() EXCEPTION HANDLING");
  }

  try {
    list2.DeleteBack();
  } catch (const string &e) {
    Test(e == "Array Empty", "DeleteBack() EXCEPTION HANDLING");
  }

  DynamicStringArray list3(758);
  Test(list3.GetSize() == 0, "DynamicStringArray(758) && GetSize()");
  Test(list3.GetCapacity() == 758, "GetCapacity()");
  Test(list3.ToString() == "", "ToString()");
  Test(list3.Empty() == true, "Empty()");

  try {
    list3.At(0);
  } catch (const string &e) {
    Test(e == "Invalid Location", "At(0) EXCEPTION HANDLING");
  }

  try {
    list3.GetFirst();
  } catch (const string &e) {
    Test(e == "Array Empty", "GetFirst() EXCEPTION HANDLING");
  }

  try {
    list3.GetLast();
  } catch (const string &e) {
    Test(e == "Array Empty", "GetLast() EXCEPTION HANDLING");
  }

  try {
    list3.DeleteFront();
  } catch (const string &e) {
    Test(e == "Array Empty", "DeleteFront() EXCEPTION HANDLING");
  }

  try {
    list3.DeleteBack();
  } catch (const string &e) {
    Test(e == "Array Empty", "DeleteBack() EXCEPTION HANDLING");
  }

  // Testing Destructors
  cout << "\n*****Testing Destructor*****" << endl
       << "If the next line is the \"END Testing Destructor\" then you passed!"
       << endl;
  DynamicStringArray *dynamic_list = new DynamicStringArray();
  delete dynamic_list;
  dynamic_list = new DynamicStringArray();
  for (int i = 0; i < 50; i++)
    dynamic_list->AddFront(new string("testing"));
  delete dynamic_list;
  cout << "*****END Testing Destructor*****" << endl << endl;
  cout << string(40, '-') << endl;
  cout << "Passed: " << ut_passed << " / " << ut_total << endl;
  OutputFailedTests();
  cout << string(40, '-') << endl;
  cout << "Unit Test Complete!\n";
  cout << string(40, '-') << endl;
}

// For testing (DO NOT ALTER)
void Test(bool test, string more_info) {
  static int test_number = 1;
  ut_total++;
  if (test) {
    cout << "PASSSED TEST ";
    ut_passed++;
  } else {
    cout << "FAILED  TEST ";
    ut_failed++;
    failed_tests.push_back(ut_total);
  }
  cout << test_number << " " << more_info << "!" << endl;
  test_number++;
}

void OutputFailedTests() {
  if (failed_tests.size()) {
    cout << "Failed test number(s): ";
    for (unsigned int i = 0; i < failed_tests.size() - 1; i++)
      cout << failed_tests.at(i) << ", ";
    cout << failed_tests.at(failed_tests.size() - 1) << endl;
  }
}
Compile:

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
$ g++ dynamic_string_array_test.cpp dynamic_string_array.cpp
dynamic_string_array_test.cpp: In function ‘void UnitTest()’:
dynamic_string_array_test.cpp:45:22: error: call of overloaded ‘DynamicStringArray()’ is ambiguous
   DynamicStringArray list;
                      ^
dynamic_string_array_test.cpp:45:22: note: candidates are:
In file included from dynamic_string_array_test.cpp:11:0:
dynamic_string_array.h:9:12: note: DynamicStringArray::DynamicStringArray(int)
   explicit DynamicStringArray(int size = 10);
            ^
dynamic_string_array.h:8:3: note: DynamicStringArray::DynamicStringArray()
   DynamicStringArray();
   ^
dynamic_string_array_test.cpp:82:36: error: no matching function for call to ‘DynamicStringArray::AddFront(std::string*)’
   list.AddFront(new string("Hello"));
                                    ^
dynamic_string_array_test.cpp:82:36: note: candidate is:
In file included from dynamic_string_array_test.cpp:11:0:
dynamic_string_array.h:14:8: note: void DynamicStringArray::AddFront(std::string)
   void AddFront(std::string str);
        ^
dynamic_string_array.h:14:8: note:   no known conversion for argument 1 from ‘std::string* {aka std::basic_string<char>*}’ to ‘std::string {aka std::basic_string<char>}’
dynamic_string_array_test.cpp:92:8: error: no match foroperator*’ (operand type is ‘std::string {aka std::basic_string<char>}’)
   Test(*list.At(0) == "Hello", "At(0)");
        ^
dynamic_string_array_test.cpp:93:8: error: no match foroperator*’ (operand type is ‘std::string {aka std::basic_string<char>}’)
   Test(*list.GetFirst() == "Hello", "GetFirst()");
        ^
dynamic_string_array_test.cpp:94:8: error: no match foroperator*’ (operand type is ‘std::string {aka std::basic_string<char>}’)
   Test(*list.GetLast() == "Hello", "GetLast()");
        ^
dynamic_string_array_test.cpp:98:3: error: no match foroperator*’ (operand type is ‘std::string {aka std::basic_string<char>}’)
   *list.At(0) = "Goodbye";
   ^
dynamic_string_array_test.cpp:102:8: error: no match foroperator*’ (operand type is ‘std::string {aka std::basic_string<char>}’)
   Test(*list.At(0) == "Goodbye", "At(0)");
        ^
dynamic_string_array_test.cpp:103:8: error: no match foroperator*’ (operand type is ‘std::string {aka std::basic_string<char>}’)
   Test(*list.GetFirst() == "Goodbye", "GetFirst()");
        ^
dynamic_string_array_test.cpp:104:8: error: no match foroperator*’ (operand type is ‘std::string {aka std::basic_string<char>}’)
   Test(*list.GetLast() == "Goodbye", "GetLast()");
        ^
dynamic_string_array_test.cpp:110:36: error: no matching function for call to ‘DynamicStringArray::AddFront(std::string*)’
   list.AddFront(new string("Hello"));
                                    ^
dynamic_string_array_test.cpp:110:36: note: candidate is:
In file included from dynamic_string_array_test.cpp:11:0:
dynamic_string_array.h:14:8: note: void DynamicStringArray::AddFront(std::string)
   void AddFront(std::string str);
        ^
dynamic_string_array.h:14:8: note:   no known conversion for argument 1 from ‘std::string* {aka std::basic_string<char>*}’ to ‘std::string {aka std::basic_string<char>}’
dynamic_string_array_test.cpp:115:38: error: no matching function for call to ‘DynamicStringArray::AddFront(std::string*)’
   list.AddFront(new string("Goodbye"));
                                      ^
dynamic_string_array_test.cpp:115:38: note: candidate is:
In file included from dynamic_string_array_test.cpp:11:0:
dynamic_string_array.h:14:8: note: void DynamicStringArray::AddFront(std::string)
   void AddFront(std::string str);
        ^
dynamic_string_array.h:14:8: note:   no known conversion for argument 1 from ‘std::string* {aka std::basic_string<char>*}’ to ‘std::string {aka std::basic_string<char>}’
dynamic_string_array_test.cpp:116:36: error: no matching function for call to ‘DynamicStringArray::AddFront(std::string*)’
   list.AddFront(new string("Hello"));
                                    ^
dynamic_string_array_test.cpp:116:36: note: candidate is:
In file included from dynamic_string_array_test.cpp:11:0:
dynamic_string_array.h:14:8: note: void DynamicStringArray::AddFront(std::string)
   void AddFront(std::string str);
        ^
dynamic_string_array.h:14:8: note:   no known conversion for argument 1 from ‘std::string* {aka std::basic_string<char>*}’ to ‘std::string {aka std::basic_string<char>}’
dynamic_string_array_test.cpp:122:8: error: no match foroperator*’ (operand type is ‘std::string {aka std::basic_string<char>}’)
   Test(*list.At(1) == "Goodbye", "At(0)");
        ^
dynamic_string_array_test.cpp:123:8: error: no match foroperator*’ (operand type is ‘std::string {aka std::basic_string<char>}’)
   Test(*list.GetFirst() == "Hello", "GetFirst()");
        ^
dynamic_string_array_test.cpp:124:8: error: no match foroperator*’ (operand type is ‘std::string {aka std::basic_string<char>}’)
   Test(*list.GetLast() == "Goodbye", "GetLast()");
        ^
dynamic_string_array_test.cpp:136:3: error: ‘stringstream’ was not declared in this scope
   stringstream ss;
   ^
dynamic_string_array_test.cpp:136:3: note: suggested alternative:
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/include/c++/ios:38:0,
                 from /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/include/c++/ostream:38,
                 from /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/include/c++/iostream:39,
                 from dynamic_string_array_test.cpp:8:
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/include/c++/iosfwd:151:37: note:   ‘std::stringstream’
   typedef basic_stringstream<char>  stringstream;
                                     ^
dynamic_string_array_test.cpp:139:7: error: ‘ss’ was not declared in this scope
       ss << "StRiNg #" << i + 1;
       ^
dynamic_string_array_test.cpp:142:7: error: ‘ss’ was not declared in this scope
       ss << "sTrInG #" << i + 1;

compile continued:

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
dynamic_string_array_test.cpp:145:5: error: ‘ss’ was not declared in this scope
     ss.str("");
     ^
dynamic_string_array_test.cpp:154:8: error: no match foroperator*’ (operand type is ‘std::string {aka std::basic_string<char>}’)
   Test(*list.At(3) == "StRiNg #3", "At(3)");
        ^
dynamic_string_array_test.cpp:155:8: error: no match foroperator*’ (operand type is ‘std::string {aka std::basic_string<char>}’)
   Test(*list.At(6) == "sTrInG #4", "At(6)");
        ^
dynamic_string_array_test.cpp:161:8: error: no match foroperator*’ (operand type is ‘std::string {aka std::basic_string<char>}’)
   Test(*list.GetFirst() == "StRiNg #9", "GetFirst()");
        ^
dynamic_string_array_test.cpp:162:8: error: no match foroperator*’ (operand type is ‘std::string {aka std::basic_string<char>}’)
   Test(*list.GetLast() == "sTrInG #10", "GetLast()");
        ^
dynamic_string_array_test.cpp:215:7: error: ‘ss’ was not declared in this scope
       ss << "StRiNg #" << i + 1;
       ^
dynamic_string_array_test.cpp:218:7: error: ‘ss’ was not declared in this scope
       ss << "sTrInG #" << i + 1;
       ^
dynamic_string_array_test.cpp:221:5: error: ‘ss’ was not declared in this scope
     ss.str("");
     ^
dynamic_string_array_test.cpp:235:8: error: no match foroperator*’ (operand type is ‘std::string {aka std::basic_string<char>}’)
   Test(*list.At(3) == "StRiNg #25", "At(3)");
        ^
dynamic_string_array_test.cpp:236:8: error: no match foroperator*’ (operand type is ‘std::string {aka std::basic_string<char>}’)
   Test(*list.At(29) == "sTrInG #28", "At(29)");
        ^
dynamic_string_array_test.cpp:242:8: error: no match foroperator*’ (operand type is ‘std::string {aka std::basic_string<char>}’)
   Test(*list.GetFirst() == "StRiNg #31", "GetFirst()");
        ^
dynamic_string_array_test.cpp:243:8: error: no match foroperator*’ (operand type is ‘std::string {aka std::basic_string<char>}’)
   Test(*list.GetLast() == "sTrInG #30", "GetLast()");
        ^
dynamic_string_array_test.cpp:258:34: error: no matching function for call to ‘DynamicStringArray::AddFront(std::string*)’
     list.AddFront(new string("A"));
                                  ^
dynamic_string_array_test.cpp:258:34: note: candidate is:
In file included from dynamic_string_array_test.cpp:11:0:
dynamic_string_array.h:14:8: note: void DynamicStringArray::AddFront(std::string)
   void AddFront(std::string str);
        ^
dynamic_string_array.h:14:8: note:   no known conversion for argument 1 from ‘std::string* {aka std::basic_string<char>*}’ to ‘std::string {aka std::basic_string<char>}’
dynamic_string_array_test.cpp:300:36: error: no matching function for call to ‘DynamicStringArray::AddFront(std::string*)’
   list.AddFront(new string("Hello"));
                                    ^
dynamic_string_array_test.cpp:300:36: note: candidate is:
In file included from dynamic_string_array_test.cpp:11:0:
dynamic_string_array.h:14:8: note: void DynamicStringArray::AddFront(std::string)
   void AddFront(std::string str);
        ^
dynamic_string_array.h:14:8: note:   no known conversion for argument 1 from ‘std::string* {aka std::basic_string<char>*}’ to ‘std::string {aka std::basic_string<char>}’
dynamic_string_array_test.cpp:310:8: error: no match foroperator*’ (operand type is ‘std::string {aka std::basic_string<char>}’)
   Test(*list.At(0) == "Hello", "At(0)");
        ^
dynamic_string_array_test.cpp:311:8: error: no match foroperator*’ (operand type is ‘std::string {aka std::basic_string<char>}’)
   Test(*list.GetFirst() == "Hello", "GetFirst()");
        ^
dynamic_string_array_test.cpp:312:8: error: no match foroperator*’ (operand type is ‘std::string {aka std::basic_string<char>}’)
   Test(*list.GetLast() == "Hello", "GetLast()");
        ^
dynamic_string_array_test.cpp:393:61: error: call of overloaded ‘DynamicStringArray()’ is ambiguous
   DynamicStringArray *dynamic_list = new DynamicStringArray();
                                                             ^
dynamic_string_array_test.cpp:393:61: note: candidates are:
In file included from dynamic_string_array_test.cpp:11:0:
dynamic_string_array.h:9:12: note: DynamicStringArray::DynamicStringArray(int)
   explicit DynamicStringArray(int size = 10);
            ^
dynamic_string_array.h:8:3: note: DynamicStringArray::DynamicStringArray()
   DynamicStringArray();
   ^
dynamic_string_array_test.cpp:395:41: error: call of overloaded ‘DynamicStringArray()’ is ambiguous
   dynamic_list = new DynamicStringArray();
                                         ^
dynamic_string_array_test.cpp:395:41: note: candidates are:
In file included from dynamic_string_array_test.cpp:11:0:
dynamic_string_array.h:9:12: note: DynamicStringArray::DynamicStringArray(int)
   explicit DynamicStringArray(int size = 10);
            ^
dynamic_string_array.h:8:3: note: DynamicStringArray::DynamicStringArray()
   DynamicStringArray();
   ^
dynamic_string_array_test.cpp:397:49: error: no matching function for call to ‘DynamicStringArray::AddFront(std::string*)’
     dynamic_list->AddFront(new string("testing"));
                                                 ^
dynamic_string_array_test.cpp:397:49: note: candidate is:
In file included from dynamic_string_array_test.cpp:11:0:
dynamic_string_array.h:14:8: note: void DynamicStringArray::AddFront(std::string)
   void AddFront(std::string str);
        ^
dynamic_string_array.h:14:8: note:   no known conversion for argument 1 from ‘std::string* {aka std::basic_string<char>*}’ to ‘std::string {aka std::basic_string<char>}’
So far, I'd only been looking at your compiler errors and resolving them, without taking a look at the code not pointed out by the errors. Just looking at all of these errors, you obviously have a ton of things wrong with your code.

Also, judging from the fact that your testing function is called UnitTest and provided by your professor... this is equivalent to your final. I'm not sure I should even be helping with it.

error: call of overloaded ‘DynamicStringArray()’ is ambiguous

All these errors are because you have a default constructor, and then another constructor with a parameter. This is usually fine, but the problem is that you gave a default value to your parameter.

As you know, you giving a default value to a parameter in a function means that you can call the function without passing in a value for the parameter. In the case of a function with only a single parameter, it means you can call the function without passing any values.

But a default constructor is for creating a new object without passing in any parameters. Do you see the problem now? How is the compiler supposed to know which constructor you're trying to call?

I may take a look at the rest of this later, I need to go right now.

EDIT:
Many of the other errors are because your professor expects your DynamicStringArray class to maintain an array of string pointers, but your class uses a string array instead.
Last edited on
Topic archived. No new replies allowed.
Pages: 12