Hi I am doing an assignment in class to get familiar with using namespaces. I am getting a few different errors although i'm not sure why, as i've done this same process in 4 other header and .cpp files w/o errors so i'm stumped. The errors are:
WriteFile.cpp: In function 'void WriteLine(CSC2100::WriteFile*, CSC2100::String*)':
WriteFile.cpp:39:27: error: invalid use of incomplete type 'struct CSC2100::String'
In file included from WriteFile.h:4:0,
from WriteFile.cpp:1;
String.h:6:11: error: forward declaration of 'struct CSC2100::String'
WriteFile.cpp:41:30: error: invalid use of incomplete type 'struct CSC2100::String'
In file included from WriteFile.h:4:0,
from Writefile.cpp:1:
String.h:6:11: error: forward declaration of 'struct CSC 2100::String'
I've thoroughly examined the code mentioned in the error and can't seem to find the problem. I've included the forward declaration at the top of the WriteFile.cpp as well as the function that the errors are in:
#include "WriteFile.h"
namespace CSC2100
{
struct WriteFile
{
ofstream output_file;
bool closed;
};
}
#include <sstream>
using namespace CSC2100;
///////////////////////////////////////////
void writeLine(WriteFile* wf, String* line)
{
if (!wf->closed && line->sz > 0)
{
wf->output_file << line->text << endl;
}
}
here is WriteFile.h :
#include "String.h"
#include <fstream>
using namespace std;
namespace CSC2100
{
struct WriteFile;
}
CSC2100::WriteFile* createWriteFile(const char* file_name);
void destroyWriteFile(CSC2100::WriteFile* wf);
void writeLine(CSC2100::WriteFile* wf, CSC2100::String* line);
void close(CSC2100::WriteFile* wf);
I'll go ahead and include String.h as it is mentioned in the error. Forward declaration of the struct in String.cpp:
namespace CSC2100
{
struct String
{
const char* text;
int sz;
};
}
and String.h:
#if !defined STRING_STRUCT
#define STRING_STRUCT
namespace CSC2100
{
struct String;
}
CSC2100::String* createString(const char* char_array);
void displayString(CSC2100::String* str);
void destroyString(CSC2100::String* str);
int length(CSC2100::String* str);
const char* getText(CSC2100::String* str);
int a_to_i(CSC2100::String* str);
float a_to_f(CSC2100::String* str);
CSC2100::String* i_to_a(int number);
CSC2100::String* f_to_a(float number);
int find(CSC2100::String* str, char delimiter, int start);
CSC2100::String* substr(CSC2100::String* str, int start, int end);
int compare(CSC2100::String* str1, CSC2100::String* str2);
The code should all be correct as the professor wrote it. All we are doing is applying a namespace to it. Any help is appreciated Thanks.