下面是我得到的编译错误以及与 em 一起出现的 header/cpp 文件。如果有人有几分钟的时间和更好的眼睛来捕捉我无法捕捉到的东西,我会永远爱他们。这可以追溯到要测试的 a3main.cpp,因此,如果您还需要该文件的参考,请大声告诉我。再次感谢!
a3.cpp: In constructor 'disk::disk(int, const char*)':
a3.cpp:12: error: invalid conversion from 'const char*' to 'char*'
a3.cpp:12: error: initializing argument 1 of 'char* strcpy(char*, const char*)'
a3.cpp: In member function 'void disk::memory(int)':
a3.cpp:26: error: expected unqualified-id before '=' token
a3.cpp:28: error: expected primary-expression before '==' token
a3.cpp: At global scope:
a3.cpp:37: error: expected initializer before 'mode'
a3.cpp:42: error: expected initializer before '*' token
a3.cpp:47: error: expected initializer before 'get_segment'
//a3.cpp
#include <iostream>
#include "disk.h"
#include <iomanip>
#include <cstring>
#include <stdlib.h>
using namespace std;
disk::disk(int num_of_segments, const char* mode)
{
memory(num_of_segments);
if(strcmp(mode, "w") || !strcmp(mode, "a"))
strcpy(mode, mode);
else
strcpy(mod, "w");
}
disk::disk()
{
memory(20);
strcpy(mod, "w");
}
void disk::memory(int num) //private, see header file
{
segment = new segment[num];
// (nothrow) - page 80 in the text
if(segment == NULL)
{
cerr << "Could not find any data in class ";
exit(0);
}
total = num;
count = 0;
}
const char* disk::get mode() const
{
return mode;
}
segment segment* disk::get_all_segment() const
{
return sgmt;
}
int disk::segment get_segment(int pos) const
{
segment temp;
if(pos > 0 && pos < count)
{
temp = segment[pos];
}
return temp;
}
int disk::get_segment_count() const
{
return count;
}
disk disk::operator+=(const segment &r)
{
if(count < total)
{
sgmt[count] = r;
count++;
}
return *this;
}
void disk::operator=(const disk &r)
{
if(*this != &r)
{
if(sgmt != NULL)
delete[] sgmt;
memory(r.total);
for(int i=0; i < r.count; i++)
{
sgmt[i] = r.sgmt[i];
}
count = r.count;
strcpy(mod, r.mod);
}
}
disk::disk(const disk& copy) //copy constructor
{
memory(copy.total);
for(int i=0; i<copy.count; i++)
{
sgmt[i] = copy.sgmt[i];
}
count = copy.count;
strcpy(mod, copy.mod);
}
disk::~disk()
{
if(*sgmt != NULL)
{
delete[] sgmt;
}
}
//disk.h
#include "segment.h"
#include <iomanip>
#include <cstring> class disk {
private:
segment *sgmt;
char mod[3];
int count, total;
void memory(int);
public:
disk(int, const char *);
disk( );
const char* get_mode( ) const;
segment get_segment(int) const;
int get_segment_count( ) const;
const segment* get_all_segments( ) const;
int access(const char [ ]);
disk operator+=(const segment &);
void operator=(const disk &);
disk(const disk &);
~disk( ); };
//segment.h
class segment
{
private:
char data[SIZE][41];
public:
void initialize(const char [][2000], int);
void initialize();
int match(const char []);
void sort();
void get_word(char [], int);
int set_word(const char [], int);
int set_char(int, int, char);
char get_char(int, int);
};