Below is the compilation errors I’m getting and the header/cpp files that go with em. If anyone has a few minutes and a better eye at catching something that I can’t, I would love them forever. This goes back to an a3main.cpp to be tested, so if you need that file fir reference as well just give me a shout. Thanks again!
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);
};
You need to just work through the errors one by one, starting at the top.
The first error is:
And the referenced line 12 is:
You declared
modeasconst char*and the error saysstrcpytakeschar*as its first argument. The error says its invalid to convertconst char*tochar*. So it should be clear that the error is that you aren’t allowed to passmodeas the first argument tostrcpy.strcpy(mode, mode);makes no sense and is not allowed.modecannot be modified but strcpy will modify it. Furthermore, you are trying to copy it over itself, which, if it worked, would do nothing.AndreyT is right about these last errors; you have to learn to just go back and re-read the code they point at and see what you did wrong.
segementinsegment = new segment[num];is a type name, in which case you can’t assign to it like this, or get its value like inif(segment == NULL). You probably meansgmt.In
const char* disk::get mode() constyou forgot an underscore.In
segment segment* disk::get_all_segment() constandint disk::segment get_segment(int pos) constyou have an extrasegments.