2012-10-09 1 views
0

오류 :내가 오류가 계속,이 클래스를 사용하여 내 처음이다, 여기 내 코드입니다 :

1>------ Build started: Project: SFML_lesson1, Configuration: Debug Win32 ------ 
1> Main.cpp 
1>c:\users\steven\documents\visual studio 2010\projects\sfml_lesson1\sfml_lesson1\keyevents.h(5): error C2146: syntax error : missing ';' before identifier 'event' 
1>c:\users\steven\documents\visual studio 2010\projects\sfml_lesson1\sfml_lesson1\keyevents.h(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
1>c:\users\steven\documents\visual studio 2010\projects\sfml_lesson1\sfml_lesson1\keyevents.h(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
1>c:\users\steven\documents\visual studio 2010\projects\sfml_lesson1\sfml_lesson1\keyevents.h(8): error C2065: 'event' : undeclared identifier 
1>c:\users\steven\documents\visual studio 2010\projects\sfml_lesson1\sfml_lesson1\keyevents.h(8): error C2228: left of '.type' must have class/struct/union 
1>   type is ''unknown-type'' 
1>c:\users\steven\documents\visual studio 2010\projects\sfml_lesson1\sfml_lesson1\keyevents.h(8): error C2653: 'Event' : is not a class or namespace name 
1>c:\users\steven\documents\visual studio 2010\projects\sfml_lesson1\sfml_lesson1\keyevents.h(8): error C2065: 'MouseButtonPressed' : undeclared identifier 
1>c:\users\steven\documents\visual studio 2010\projects\sfml_lesson1\sfml_lesson1\keyevents.h(8): error C2065: 'event' : undeclared identifier 
1>c:\users\steven\documents\visual studio 2010\projects\sfml_lesson1\sfml_lesson1\keyevents.h(8): error C2228: left of '.mouseButton' must have class/struct/union 
1>   type is ''unknown-type'' 
1>c:\users\steven\documents\visual studio 2010\projects\sfml_lesson1\sfml_lesson1\keyevents.h(8): error C2228: left of '.button' must have class/struct/union 
1>c:\users\steven\documents\visual studio 2010\projects\sfml_lesson1\sfml_lesson1\keyevents.h(8): error C2653: 'Mouse' : is not a class or namespace name 
1>c:\users\steven\documents\visual studio 2010\projects\sfml_lesson1\sfml_lesson1\keyevents.h(8): error C2065: 'Left' : undeclared identifier 
1>c:\users\steven\documents\visual studio 2010\projects\sfml_lesson1\sfml_lesson1\main.cpp(47): error C3867: 'input::leftclick': function call missing argument list; use '&input::leftclick' to create a pointer to member 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

이것은 과거에, 나는 C++를 학습 한 다음과 같은 물건을 내 처음으로 몇 주,하지만 이상한 오류가 발생했습니다. SFDML을 사용하여 게임 개발자의 기본 사항을 이해합니다. 왼쪽 트리거 이벤트를 사용하는 간단한 방법을 작성한 다음 긴 줄을 작성하기로했습니다. 여기

class input{ 

public: 

    Event event; 

    int leftclick(){ 
    event.type == Event::MouseButtonPressed && event.mouseButton.button == Mouse::Left; 

    return true; 
    } 

}; 

하여 Main.cpp 파일은 다음과 같습니다 :

여기 파일 내 KeyEvents.h입니다

//Libraries 
#include <iostream> 
#include <SFML/Graphics.hpp> 
#include "Settings.h" // Includes the Settings.h file located in the "Header Files" folder 
#include "KeyEvents.h" 
using namespace std; 
using namespace sf; 


int main(){ 
    // Declarations 
    bool Playing=true; // Used for the Main loop when the game starts up 
    // The datatype holding all the events 
    Event event; 

    RenderWindow window(VideoMode(Settings::WIDTH,Settings::HEIGHT), "Project"); // Creates the windows 

    window.setFramerateLimit(Settings::FRAME_RATE); // Sets the Frame-rate limit 
    window.setKeyRepeatEnabled(Settings::KEY_REPEATE); // Remove spamming keys 
    while(Playing==true){ // Main loop 


      while (window.pollEvent(event)){ 

       if(event.type == Event::KeyPressed){ // If a Key has been pressed! 
         // For certain keyboard buttons it would be 'event.key.code == Keyboard::A' 
          // There are two states for the keyboard 'KeyPressed' and 'KeyRelease' 

        cout << "A Key has been pressed!\n"; 

       } 
       else if(event.type == Event::KeyReleased){ 

         cout << "The key has just been released!\n"; // This message only pops up when they 'A' or 'a' has been released 


        } 


       if(event.type == Event::KeyReleased && event.key.code == Keyboard::Escape){ // This is for when the 'event' is closed the game will exit, by making the bool 'Playing' to false it is set to close by using the escape key 

        cout << "The Game has just been closed when Pressing the 'Escape Key'\n"; 
        Playing=false; 

       } 

       if(input::leftclick){ // My custom way of knowing when the user left clicks with his/her mouse inside the class input there is a function called leftclick 

       cout << "YAY I AM LEARNING\n"; 


       } 


      } 

     // Logic: 


     // Rendering: 

    // Clears the window, then displays what it needs to 
    window.clear(); 
    window.display(); 

    } 

    window.close(); // Closes the window. when Playing is false 

// Returns tto the computer that the program is running fine. 
return true; 
} 

그 것 같아요 이상한 오류입니다.

+0

변수에 "이벤트 이벤트; 그것을 할당하거나 새로운 인스턴스를 생성 한 적이 없으며, 어떻게 그 값을 테스트 할 수 있습니까? –

+0

몇 가지 문제가있는 것 같습니다. 로그를 읽고 하나씩 수정해야합니다. 예를 들어 [구문 오류 : 누락 된 ';' 식별자 '이벤트'전에]. '누락 된 것 같습니다.' 어딘가에. – awm

+0

나는 ';'을 놓치지 않았습니다. 어딘가에. 나는 두 번 확인했다. –

답변

1

Event 클래스가 사용되기 전에 정의되거나 선언되지 않은 것으로 보입니다. 어디에서 신고합니까?

0

컴파일러 오류로 Event 유형이 정의되지 않았습니다. KeyEvents.h의 시작 부분에 정의가있는 머리글을 포함해야합니다. 그리고 네임 스페이스 범위 해상도를 사용하는 것을 잊지 마세요 :

#include <SFML/Event.hpp> 

class input{ 
public: 
    sf::Event event; 

    // Other code 
    ... 
}; 

또한이 글로벌 using 지시어를 사용하지 않는 것이 좋습니다 언급하고 싶습니다. 기능 범위 내에서 로컬로 작성하십시오.

+0

글로벌 사용 지시문을 사용하는 것이 권장되지 않는 이유는 무엇입니까? 또한이 오류는 1> c : \ users \ steven \ documents \ visual studio 2010 \ projects \ sfml_lesson1 \ sfml_lesson1 \ keyevents.h (1) : 심각한 오류 C1083 : 포함 파일을 열 수 없습니다 : 'SFML/event.hpp': 그러한 파일이나 디렉토리가 없습니다. –

+0

또 다른 오류가 있습니다 : 'input :: leftclick': 함수 호출 누락 된 인수 목록; '& input :: leftclick'을 사용하여 멤버에 대한 포인터를 생성하십시오. –

+0

@StevenJGarcia SFML 폴더가 프로젝트 포함 경로에 있습니까? 프로젝트 등록 정보 -> C/C++ -> 일반 -> 추가 포함 디렉토리. 또는 VC 전역 디렉토리 : Options -> Projects and Solutions -> VC++ Directories -> Include files – Rost