C1001编译类对象的创建错误

时间:2015-09-06 17:40:59

标签: c++ c1001

当我使用Game newGame;创建以下类的实例时,它会抛出一个c1001错误,指出存在编译器错误。

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;
}

完成错误代码:
严重性代码描述项目文件行 错误C1001编译器中发生内部错误。 CityOfDwarves C:\ Users \ Daniel \ Documents \ Visual Studio 2015 \ Projects \ CityOfDwarves \ CityOfDwarves \ main.cpp 1

0 个答案:

没有答案