在Paw中保存新项目时,出现错误Paw Version 3.1.10 (Retail)
,并且该项目未保存。如何解决这个问题?我在macOS Catalina 10.15.1 (19B88)
上使用//headers
#include <iostream>
#include <string>
using namespace std;
//Class Declaration
class DynamicStringArray {
//private variables
private:
//needs to be a pointer
string *dynamicArray;
int size;
public:
//public functions
DynamicStringArray();
DynamicStringArray(const DynamicStringArray& array);
int getSize();
void addEntry(string entry);
bool deleteEntry(string entry);
string getEntry(int index);
void operator= (const DynamicStringArray& equals);
~DynamicStringArray();
};
//default constructor
DynamicStringArray::DynamicStringArray() {
dynamicArray = new string[0];
size = 0;
}
//copy constructor
DynamicStringArray::DynamicStringArray(const DynamicStringArray& array) {
//makes their size equal
size = array.size;
dynamicArray = new string[size];
//copies the data over.
for (int i = 0; i < size-1; i++) {
dynamicArray[i] = array.dynamicArray[i];
}
}
//accessor method to get the size
int DynamicStringArray::getSize() {
return size;
}
//adding an entry
void DynamicStringArray::addEntry(string entry) {
string *tempArray = new string[size + 1];
for (int i = 0; i < size; i++) {
tempArray[i] = dynamicArray[i];
}
//increment size
size++;
tempArray[size] = entry;
//set dynamic array to the temp
delete[] dynamicArray;
dynamicArray = tempArray;
//cleanup
delete[] tempArray;
}
//delete entry
bool DynamicStringArray::deleteEntry(string entry) {
bool found = false;
bool replaced = false;
int index;
//checks for the value
for (int i = 0; i < size; i++) {
if (dynamicArray[i] == entry) {
found = true;
index = i;
}
}
if (!found) {
return found;
}
//declaring temp array
string *tempArray = new string[size - 1];
//copies data over, skipping over the one not being coppied.
for (int i = 0; i < size; i++) {
if (!replaced) {
tempArray[i] = dynamicArray[i];
}
else if (replaced) {
tempArray[i - 1] = dynamicArray[i];
}
if (i == index) {
replaced = true;
}
}
//setting dynamic array to the temp
delete[] dynamicArray;
dynamicArray = tempArray;
//de-increment
size--;
//cleanup
delete[] tempArray;
return true;
}
//accessor method to get the value at an index.
string DynamicStringArray::getEntry(int index) {
return dynamicArray[index];
}
void DynamicStringArray::operator= (const DynamicStringArray& equals) {
//makes their size equal
size = equals.size;
dynamicArray = new string[size];
//copies the data over.
for (int i = 0; i < size; i++) {
dynamicArray[i] = equals.dynamicArray[i];
}
}
DynamicStringArray::~DynamicStringArray() {
delete[] dynamicArray;
dynamicArray = NULL;
}
int main()
{
DynamicStringArray* test = new DynamicStringArray;
cout << test->getSize() << endl;
test->addEntry("joe");
cout << test->getSize() << endl;
return 0;
}
。谢谢。