简体   繁体   English

从GCC随附的标头中获取语法错误

[英]Getting syntax errors from a header included with GCC

I am using Sleep from Windows.h, and when I go to compile it is giving me these errors. 我正在使用Windows.h中的Sleep,在我进行编译时会出现这些错误。 I tried googling them and found nothing. 我尝试使用Google搜索,但一无所获。 Also i wouldn't expect there to be issues like this from the include files from GCC. 我也不希望GCC的包含文件中有这样的问题。 Can anyone tell me what these errors could be from. 谁能告诉我这些错误可能来自什么。

edit: with a lot of this code it is unfinished, but wanted to get it tested partially. 编辑:大量的这段代码尚未完成,但希望对其进行部分测试。 I mainly just wanted an idea of the type of screw up on my end to look for because I have no idea where to start. 我主要只是想弄清楚这种类型的想法,因为我不知道从哪里开始。

>g++ -o test.exe main.cpp

In file included from C:/TDM-GCC-64/x86_64-w64-mingw32/include/windows.h:65:0,
                 from main.cpp:3:
C:/TDM-GCC-64/x86_64-w64-mingw32/include/excpt.h:14:8: error: expected unqualified-id before string constant
 extern "C" {
        ^
In file included from C:/TDM-GCC-64/x86_64-w64-mingw32/include/windows.h:65:0,
                 from main.cpp:3:
C:/TDM-GCC-64/x86_64-w64-mingw32/include/excpt.h:128:18: error: expected '}' before end of line
C:/TDM-GCC-64/x86_64-w64-mingw32/include/excpt.h:128:18: error: expected unqualified-id before end of line
C:/TDM-GCC-64/x86_64-w64-mingw32/include/excpt.h:128:18: error: expected declaration before end of line

here is the main: 这是主要的:

#include "program/skull_ascii.h"
#include "Player.h"
//#include "Building.h"

#include "Windows.h"
#include <iomanip>
#include <stdlib.h>
#include <string>

//prototypes
void intro();
void cityScene(Player*);
Player* getUserInfo();
void scroll(std::string text);

int main(){
    intro(); //flashy ascii text intro
    player* user = getUserInfo();
    cityScene(user);

}


void intro(){ //not done tweaking
    system("mode con:cols=81 lines=30");
    system("color 02");
    skull_title();
    Sleep(1000);
    for(int i = 1; i < 15; i++){
        system("color 04");
        Sleep(i*i / 2);
        system("color 02");
        Sleep(i*i);
    }   
    system("color 04");
    system("pause");
    system("cls");
    system("mode con:cols=120 lines=30");
}

Player* getUserInfo(){ //not done, just enough to test
    player* user = new Player("test", 56);
    return user;
}

void cityScene(Player* user){ //not close to finished, but shouldn't cause any issue
    std::string prompt = "arbitrary text"; // will print out with other function    

    system("pause");
    system("cls");

    std::cout << "what do you want to do?: \n"
    std::cout << "\t1.Just relax its not that important\n";
    std::cout << "\t2.scavenge the apartment for items\n";
    std::cout << "\t3.Leave immediately, there's no time left\n";
    std::cout << ":";
}

void scroll(std::string text){
    for(int i = 0; i < text.length(); i++){
        std::cout << text[i];
        Sleep(200);
        if(i%45 == 0) std::cout << "\n"; 
    }
}

the player class is a messy container atm, and isn't done here is the player class: 播放器类是一个凌乱的容器atm,而播放器类没有在这里完成:


#pragma once

#include <string>
#include <list>
#include <iostream>
#include "Item.h"

class Player{

    std::string name;
    int age;

    std::list<Item> inventory;

    public:

    Player(std::string n, int a){
        this->name = n;
        this->age = a;
    }

    /*  F-name: updateScreen()
        params: none
        return: void
        purpos: updates the play screen with current player information
    */void update(){
        system("cls"); // clear screen
        std::cout << "NAME:" << name << "  |\
            AGE:XXX  | \
            WEAPONS: weapon 1, weapon2  | \
            PACK_WEIGHT:XXXXXXXKgs  | \
            PARTY: name1, name2, name3, name4  | \
            LOCATION:  big city"; 
    }



    /*  
    F-name: addItem()
    params: item object to add
    return: void
    purpos: adds an item to the inventory list
    */ void addItem(Item newItem){}

#pragma once

#include <iostream>
#include <string>


class Item{
    std::string name;
    std::string desc;


    public:

    Item(){ 
        name = "void";
        desc = "void";
    }

    Item(const Item& copy){
        this->name = copy.name;
        this->desc = copy.desc;

    }

    Item(std::string n, std::string d){
        name = n;
        desc = d;
    }

    ~Item(){}


    friend std::ostream& operator<< (std::ostream& out, const Item& thing){
        out << thing.name;
        return out;
    }


    void setName(std::string n){name = n;}
    void setDesc(std::string d){desc = d;}

    std::string getName(){return name;}
    std::string getDesc(){return desc;}

};

The Player class definition in Player.h is not closed correctly. Player.hPlayer类定义未正确关闭。 You forgot to add: 您忘记添加:

};

at the end. 在末尾。 Right now, this causes the next header you include to cause a compilation error. 现在,这将导致您包含的下一个标头导致编译错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM