0

I am having an issue when trying to compile a main file using headers, Splash_Screen.h and record.h. The compiler is returning "error: 'Record_window' was not declared in this scope" (in Splash_Screen.h), when looking at the code I understand that there is no Record_window in Splash_Screen.h, but if I type '#include "record.h"' in Splash_Screen.h it gives me a "nested too deep" error. I am unsure what to do at this point, and would love it if someone could assist me.

Splash_Screen.h:

#include "GUI.h"
#include "std_lib_facilities_4.h"
#include "Simple_window.h"
#include "Graph.h"

using namespace Graph_lib;


struct splash_screen : Graph_lib:: Window {
    splash_screen(Point xy, int w, int h, const string& title);

    Image background {Point{0,0},"background.jpg"};

    Text ti{Point{210,100},"Team Name"};


    Rectangle play_rec{Point{250,380},77,20};
    Text play_text{Point{255,395},"Play Game"};
    Rectangle instr_rec{Point{350,380},85,20};
    Text instr_text{Point{355,395},"Instructions"};
    Rectangle high_rec{Point{150,380},80,20};
    Text high_text{Point{155,395},"Highscores"};

private:
    Button play_button;
    Button instr_button;
    Button highscore_button;

    int play();
    int quit();
    int instr();
    int highscore();
};

splash_screen::splash_screen(Point xy, int w, int h, const string& title)
    :Window(xy,w,h,title),
    play_button{Point{250,380},77,20,"Play", 
    [](Address, Address pw) {reference_to<splash_screen>(pw).play();}},
    instr_button{Point{350,380},85,20,"Instuctions",
    [](Address, Address pw) {reference_to<splash_screen>(pw).instr();}},
    highscore_button{Point{150,380},80,20,"Highscores",
    [](Address, Address pw) {reference_to<splash_screen>(pw).highscore();}}

{
    attach(play_button);
    attach(instr_button);
    attach(highscore_button);
    attach(background);
    ti.set_color(Color::white);
    attach(ti);
    play_rec.set_fill_color(Color::white);
    attach(play_rec);
    play_text.set_color(Color::black);
    attach(play_text);
    instr_rec.set_fill_color(Color::white);
    attach(instr_rec);
    instr_text.set_color(Color::black);
    attach(instr_text);
    high_rec.set_fill_color(Color::white);
    attach(high_rec);
    high_text.set_color(Color::black);
    attach(high_text);


}

int splash_screen::play()
{
    hide();
    return gui_main();
}

int splash_screen::highscore()
{
    hide();
    Record_window win{Point{100,100},600,400,"Project"};
    return gui_main();
}

int splash_screen::instr()
{
    hide();
    Simple_window win{Point{100,100},600,400,"canvas"};
    return gui_main();
}

record.h:

#include "GUI.h"
#include "std_lib_facilities_4.h"
#include "Simple_window.h"
#include "Graph.h"
#include "Splash_Screen.h"



using namespace Graph_lib;




vector<string> Read_Records(){
    ifstream ist {"records.txt"};
    vector<string> records;
    string recordLine;
    while(ist >> recordLine){
        records.push_back(recordLine);
    }
    return records;
}


vector<Text*> Create_Rec_Text(vector<string> x){
    vector<Text*> return_Vector;
    int j = 275;
    int k = 100;
    for(int i = 0; i < x.size(); i = i +2){
        if(i == 10){
            j = j - 2;
        }
        String text_String = x[i] + ' ' + x[i+1];
        Text *record = new Text(Point(j, k), text_String);
        return_Vector.push_back(record);
        k = k + 50;
    }   
    return return_Vector;
}





struct Record_window : Graph_lib::Window { 
    Record_window(Point xy, int w, int h, const string& title);
    private:
        In_box user_initials;
        Button enter_button;
        Button next_button;
        Button second_next;
        Text init_title;
        Text init_line2;
        Text title;
        void next();
        int snd_next();
        void enter();
};

Record_window::Record_window(Point xy, int w, int h, const string& title) : Graph_lib::Window{xy, w,h,title},
    next_button{Point{x_max()-70,0}, 70, 20, "Next", [ ] (Graph_lib::Address, Graph_lib::Address pw) {Graph_lib::reference_to<Record_window>(pw).next();}},
    second_next{Point{x_max()-70,0}, 70, 20, "Main Menu", [ ] (Graph_lib::Address, Graph_lib::Address pw) {Graph_lib::reference_to<Record_window>(pw).snd_next();}},
    enter_button{Point(280,210), 40, 20, "Enter", [ ] (Graph_lib::Address, Graph_lib::Address pw) {Graph_lib::reference_to<Record_window>(pw).enter();}},
    user_initials{Point(275, 190), 50, 20, "Initials:"},
    title{Point(245, 50), "Top Scores"},
    init_title{Point(225, 120), "Please enter your initials"},
    init_line2{Point(170, 135), "so it can be recorded if you beat a top score."}
{
    attach(init_title);
    attach(init_line2);
    attach(user_initials);
    attach(enter_button);
    attach(next_button);
}



void Record_window::next()
{
    detach(init_title);
    detach(init_line2);
    detach(user_initials);
    detach(enter_button);
    detach(next_button);
    title.set_font_size(24);
    attach(title);
    attach(second_next);
    vector<string> records = Read_Records();
    vector<Text*>  text_Records = Create_Rec_Text(records);
    for(int i = 0; i < text_Records.size(); i++){
        attach(*text_Records[i]);
    }
}

int Record_window::snd_next()
{
    hide(); //moves back to main menu
    splash_screen splash{Point(100, 100), 600, 400, "Main Menu"};
    return gui_main();
}

void Record_window::enter()
{
    vector<string> records = Read_Records();
    ofstream record_file;
    record_file.open("records.txt");
    for(int i = 0; i < records.size() - 2; i = i +2){
        record_file << records[i] + ' ' + records[i+1] + "   ";
    }
    String act_string = user_initials.get_string();
    record_file << act_string + ' ' + "N/A";
    record_file.close();    
}
Jose
  • 3
  • 2
  • What does `#include` do? (I'm sure someone will ask me why I don't know; I do know, I'm asking you) – user253751 Apr 13 '16 at 03:04
  • @Jose this might help: http://stackoverflow.com/questions/2979384/purpose-of-header-guards ... also this: http://stackoverflow.com/a/4757718/1553090 – paddy Apr 13 '16 at 03:11
  • From what I understand, it replaces the #include with whatever code is in the file after the #include, this leads me to believe I may know the solution... – Jose Apr 13 '16 at 03:14

0 Answers0