2017-04-25 8 views
-6
World::World() { 
    int width = -1; 
    int height = -1; 

    cout << "Aby rozpoczac gre wpisz rozmiar planszy" << endl; 
    cout << "Aby uruchomic domyslne romiary zostaw pole puste" << endl; 

    cout << "Podaj szerokosc: "; 
    // I don't see what i'm typing and i need to press enter twice; 
    cin >> width; 

    cout << "Podaj wysokosc: "; 
    // I don't see what i'm typing too and make my program crash 
    cin >> height; 

    World(height, width); 
} 

couts은 훌륭하지만 cin은 soooo buged입니다. 첫 번째 cin은 입력하는 내용이 표시되지 않고 enter를 두 번 눌러야합니다. 내가 너무 아무것도 표시되지 않으며 내가 어떤 키, 프로그램이 다운C++ <iostream> cin 제대로 작동하지 않습니다.

+0

코드입니다. 너의 문제는 다른 곳에있다. –

+1

'세계 (높이, 너비);는 무엇이라고 생각하십니까? –

+1

제 조언은 디버거 사용법을 배우는 것입니다. 그리고 어떤 종류의 컴파일러 나 시스템 버그를 찾았다 고 생각하지 마십시오. – drescherjm

답변

1

라인을 누른 상태

World(height, width); 

임시 객체를 생성하고이를 폐기 CIN secend 동안. 현재 개체의 멤버 변수가 제대로 초기화되지 않습니다.

코드를 단순화하십시오. 코드를 이동하여 입력 데이터를 호출하는 함수로 가져옵니다. 예를 들어, main에서 사용하십시오.

int width = -1; 
int height = -1; 

cout << "Aby rozpoczac gre wpisz rozmiar planszy" << endl; 
cout << "Aby uruchomic domyslne romiary zostaw pole puste" << endl; 

cout << "Podaj szerokosc: "; 
// I don't see what i'm typing and i need to press enter twice; 
cin >> width; 

cout << "Podaj wysokosc: "; 
// I don't see what i'm typing too and make my program crash 
cin >> height; 

World w(height, width); 

는 (실제 멤버 변수로 heightMemberwidthMember 교체) 기본 생성자를 단순화 : 당신이 우리 일을해야 보여주는 것

World::World() : heightMember(0), widthMember(0) {}