以下は、私が取得しているコンパイルエラーと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);
};