0

When I Create An Instance of the following class using Game newGame; it throws a c1001 error stating that there was a compiler error.

game.h:

#pragma once

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <conio.h>
#include "cls.h"
#include "explode.h"

using namespace std;

class Game
{
private:
    explode EXP;
    CLS cls;
    string _SaveGame, _DIRECTORY;
    int _GAMEDATA[500];
    string _DATATITLES[500] = { "Ticks", "Dwarves", "Grain Mills", "Lumber Mills", "Mines", "Grain Workers", "Lumber Workers", "Mine Workers", "Grain Mill Experts", "Lumber Mill Experts", "Mine Experts" };

public:

    void CS() 
    { 
        cls.clear(); 
    }

    void SetSaveName(string SaveName)
    {
        _SaveGame = SaveName;
    }

    void init(string directory)
    {
        _DIRECTORY = directory;
        cout << "Init Game" << endl;
        CS();

        ofstream gameSave;
        gameSave.open(_DIRECTORY + _SaveGame + ".save", ofstream::out | ofstream::app);
        cout << "Game Saved As: " << _DIRECTORY + _SaveGame + ".save";
        if (!gameSave.good())
        {
            // Write New Data To File
            cout << "Game Saved As: " << _DIRECTORY + _SaveGame + ".save";
            gameSave.flush();
            gameSave << "0\n"; // TICKS
            gameSave.flush();
            gameSave << "7\n"; // Dwarves
            gameSave.flush();
            gameSave << "1\n"; // Grain Mills
            gameSave.flush();
            gameSave << "1\n"; // Lumber Mill
            gameSave.flush();
            gameSave << "1\n"; // Mine
            gameSave.flush();
            gameSave << "2\n"; // Grain Mill Workers
            gameSave.flush();
            gameSave << "2\n"; // Lumber Mill Workers
            gameSave.flush();
            gameSave << "3\n"; // Mine Workers
            gameSave.flush();
            gameSave << "1\n"; // Grain Mill Experts
            gameSave.flush();
            gameSave << "1\n"; // Lumber Mill Experts
            gameSave.flush();
            gameSave << "1\n"; // Mine Experts
            gameSave.flush();

            gameSave << "ENDFILE";
            gameSave.flush();

        }
        else
        {
            // Read Data From File
            loadGame(_SaveGame);
        }

        bool GameLoop = true;
        while (GameLoop)
        {
            // Begin Game Loop Instance
            printData();
            string in;
            bool parseDataLoop = 1;
            while (parseDataLoop)
            {
                in = getData();
                int parseDataInt = parseData(in);
                if (parseDataInt == 1) {
                    GameLoop = 0;
                    saveGame();
                    exit(0);
                }
                else if (parseDataInt == 2) {
                    _getch();
                }
                else
                {
                    parseDataLoop = 0;
                }
            }
            saveGame();
        }

    }

    void GameTick()
    {
        _GAMEDATA[0] += 1; // Number Of Game Ticks

    }

    void printData()
    {
        CS();
        for (int i = 0; i < 500; i++) {
            if (_GAMEDATA[i] != NULL) {
                cout << _DATATITLES[i] << " : " << _GAMEDATA[i];
            }
        }
    }

    string getData()
    {
        string DATA;

        cin >> DATA;

        return DATA;
    }

    int parseData(string input)
    {

        int quit = 0;
        if (input == "help")
        {
            // Print List Of Commands And Descriptions: 
            cout << "List Of All Available Commands:" << endl;
            cout << "help : Shows A List Of All Available Commands" << endl;
            cout << "tick : Makes Game Progress One Tick" << endl;
            cout << "tick.NUM : Makes Game Progress NUM Tick(s)" << endl;
            cout << "quit : Saves Game And Terminates Program" << endl;
            quit = 2;
        }
        else if (input == "quit")
        {
            quit = 1;
        }
        else if (input == "tick")
        {
            // Skip One Tick

            GameTick();
        }
        else if (find(input, '.')) {
            vector<string> output;
            output = EXP.explodeStuff(input, '.');

            if (output[0] == "tick") {
                if (isInterger(output[1]))
                {
                    for (int i = 0; i < stoi(output[1]); i++) {
                        GameTick();
                    }
                }
                else
                {
                    cout << "ERROR: tick." << output[1] << ", is not vaid please use numbers not letters." << endl;
                    quit = 2;
                }
            }
        }
        else
        {
            cout << "ERROR: Invalid Command Please type \"help\" To See A List Of Available Commands." << endl;
            quit = 2;
        }

        return quit;
    }

    void loadGame(string saveGame)
    {
        ifstream inData;
        string temp;
        inData.open(_DIRECTORY + saveGame + ".cod");
        if (inData.good())
        {
            for (int i = 0; i < 500; i++) {
                getline(inData, temp);
                if (temp == "ENDFILE") { break; }
                if (temp != "")
                {
                    _GAMEDATA[i] = stoi(temp);
                }
            }
            inData.close();
        }
    }

    void saveGame()
    {
        // Update Data in file

        ofstream gameSave(_DIRECTORY + _SaveGame + ".save");
        gameSave.clear();
        for (int i = 0; i < 500; i++) {
            if (_GAMEDATA[i] != NULL) {
                gameSave << _GAMEDATA[i];
            }
        }
        gameSave << "\nENDFILE";
    }

    bool find(string input, char find)
    {
        bool RETURN = 0;

        for each (char CHAR in input)
        {
            if (CHAR == find) {
                RETURN = 1;
                break;
            }
        }

        return RETURN;

    }

    inline bool isInterger(const std::string & s)
    {
        if (s.empty() || ((!isdigit(s[0])) && (s[0] != '-') && (s[0] != '+'))) return false;
        char* p;
        strtol(s.c_str(), &p, 10);
        return (*p == 0);
    }

};

main.cpp:

#include <iostream>
#include <fstream>
#include <string>
#include <vector>

#include "game.h"
#include "programSettings.h" 
#include "cls.h"
#include "explode.h" // Adds explode(string input, char delimeter), and explodePrint(vector<string> input)

using namespace std;

string _DIRECTORY = (string)getenv("APPDATA") + "/cityOfDwarves/";
vector<int> _SETTINGS; // Array To Hold All Settings In The SETTINGS.cod File
int SettingsConfigured;
explode EXP;
CLS cls;

int main()
{

    SetConsoleTitle("CityOfDwarves");

    programSettings pSet(_DIRECTORY);

    _SETTINGS = pSet.readSettings();
    if (_SETTINGS.size() > 0) {
        SettingsConfigured = _SETTINGS[0];
    }
    else
    {
        SettingsConfigured = 0;
    }

    if (!SettingsConfigured) {
        pSet.setSettings();
    }

    cout << "Settings Configured" << endl;
    cls.clear();

    cout << "Please Enter a Save Name:" << endl;
    string SaveName;
    cin >> SaveName;
    cout << "Using: " << SaveName << ", As The Current Save File." << endl;

    // Begin Game Loop
    Game mainGame;
    mainGame.SetSaveName(SaveName);
    mainGame.init(_DIRECTORY);

    char i;
    cin >> i;

    return 0;
}

Complete Error Code:
Severity Code Description Project File Line Error C1001 An internal error has occurred in the compiler. CityOfDwarves C:\Users\Daniel\Documents\Visual Studio 2015\Projects\CityOfDwarves\CityOfDwarves\main.cpp 1

  • Unrelated to your problem, but symbol names with a leading underscore followed by a capital letter [are reserved in any scope](http://stackoverflow.com/a/228797/440558). – Some programmer dude Sep 06 '15 at 17:45
  • 2
    As for your problem, start commenting out as much code as possible and make sure you don't get the error, then put it back one bit at a time until the error returns. Then at least you know which part of the code causes the error. Then simply narrow it down the same way until you know which line, statement or even sub-expression causes the problem.Then try to create a *minimal* example that causes the error, and edit your question to show that small piece of code. – Some programmer dude Sep 06 '15 at 17:49
  • Ok will try that and report back later – TNTWZRD Sep 06 '15 at 18:27
  • By definition an internal compiler error indicates a bug in the compiler. You should report it to Microsoft. (This is only moderately painful.) – Alan Stokes Sep 06 '15 at 18:32

0 Answers0