"warnings" im Code : Kein Zeilenumbruch bei Vollbild
-
Vll. kann sich jemand ja noch an meinen Weltraumvernichtungssimulator erinnern, um denn geht es jetzt nämlich. Und zwar gibts n paar warnings, aber ich weiß nicht genau warum.
main.cpp
#include "game.hpp" #include "operators.hpp" #include "events.hpp" #include "ic.hpp" using namespace std; using namespace ic; using namespace shorties; int main() { con.enableWndFSMode(); game wus; wus.run(); int counter=0; while(1) { if (counter<wus.get_vector()) { wus.set_story(counter); ++counter; } } return 0; }game.hpp
#ifndef INCLUDE_GAME_HPP #define INCLUDE_GAME_HPP #include <vector> #include <string> #include <limits> class game { public: game(); ~game(); struct part { const game * get_parent() const {return m_parent;} std::string m_question[3], m_a, m_b, m_c, m_effect[3]; part(const game *parent_, const std::string& question1_,const std::string& question2_,const std::string& question3_, const std::string& a_,const std::string& b_,const std::string& c_, const std::string& effect1_,const std::string& effect2_,const std::string& effect3_); private: const game *m_parent; }; inline void new_story(const part& data) {m_story.push_back(data);} void set_story(size_t index); void run(); inline short get_save() const {return m_save;} inline size_t get_vector() const {return m_story.size();} friend std::ostream& operator<< (std::ostream& out, const game::part& data); private: std::vector<part> m_story; const std::string m_message; short m_save; }; #endif // GAME_HPP_INCLUDEDgame.cpp
#include <iostream> #include "game.hpp" game::game() :m_message("Du bist doch Deutschlands d\x81mmster! Ist es so schwierig eine Zahl zwischen\n1 und 3 einzugeben?" + std::string(" Probiers nochmal du Arschloch!\n")),m_save(1) { } game::~game() { } game::part::part(const game *parent_, const std::string& question1_, const std::string& question2_, const std::string& question3_, const std::string& a_,const std::string& b_,const std::string& c_, const std::string& effect1_,const std::string& effect2_="",const std::string& effect3_="") :m_parent(parent_),m_a(a_),m_b(b_),m_c(c_) { m_question[0]=question1_; m_question[1]=question2_; m_question[2]=question3_; m_effect[0]=effect1_; m_effect[1]=effect2_; m_effect[2]=effect3_; } void game::set_story(size_t index) { std::cout << m_story[index]; while(!(std::cin >> m_save) || (m_save>3) || (m_save<1)) { std::cin.clear(); std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); std::cout << m_message; } if (m_story[index].m_effect[1].empty() == true && m_story[index].m_effect[2].empty() == true) { std::cout << m_story[index].m_effect[0]; return; } std::cout << m_story[index].m_effect[m_save-1]; }operators.hpp
#ifndef OPERATORS_HPP_INCLUDED #define OPERATORS_HPP_INCLUDED #include <iostream> #include "game.hpp" std::ostream& operator<< (std::ostream& out, const game::part& data); #endif // OPERATORS_HPP_INCLUDEDoperators.cpp
#include "operators.hpp" std::ostream& operator<< (std::ostream& out, const game::part& data) { out << data.m_question[data.get_parent()->get_save()-1] << data.m_a << data.m_b << data.m_c; return out; }story.cpp
#include "game.hpp" void game::run() { new_story(game::part(this, "Wer wollen sie sein?\n","","", "1. Hitler\n","2. Ghandi\n","3. Georg W. Bush\n", "Sie sind nun Hitler!\n", "Sie sind nun Ghandi!\n", "Sie sind nun Georg W. Bush!\n")); ...... ....... //restlichen Text erspar ich euch^^ ........ }ic.hpp
IMPROVED CONSOLEhttp://web56.hermes.server-pool.de/pages/ic.c-plusplus.net/
ic.cpp
IMPROVED CONSOLEhttp://web56.hermes.server-pool.de/pages/ic.c-plusplus.net/
WARNINGS:
-------------- Build: Debug in GAME ---------------
Compiling: ic.cpp
Compiling: main.cpp
Compiling: operators.cpp
Compiling: story.cpp
Compiling: game.cpp
game.hpp: In constructorgame::part::part(const game*, const std::string&, const std::string&, const std::string&, const std::string&, const std::string&, const std::string&, const std::string&, const std::string&, const std::string&)': game.hpp:23: warning:game::part::m_parent' will be initialized after
game.hpp:17: warning: `std::string game::part::m_a'
game.cpp:22: warning: when initialized here
Linking console executable: .\GAME.exe
Process terminated with status 0 (0 minutes, 2 seconds)
0 errors, 3 warnings2. PROBLEM:
Seit dem ich Vollbildmodus habe, also "con.enableWndFSMode();" (die Funktion aus der improved console) wird ein Text wenn er über das Zeilenende geht nicht mehr eine Zeile weiter unten drunter geschrieben, sondern es wird einfach am Zeilenanfang wieder weitergeschriebn, und somit die Zeile teils überschrieben...
Wie kann ich das verhindern? Warum passiert das überhaupt?
-
Die Warnings kommen aus der Initialisierungsliste deines C'tors.
Die Elemente werden in der Reihenfolge erzeugt, in der sie deklariert(?) wurden und der g++ warnt, wenn sie in einer anderen Reihenfolge in der Initialisierungsliste auftauchen.
Fehler entstehen z.B. bei folgendem Code:
class foo { int bar; int foobar; foo() : foobar(2), bar(foobar)//foobar noch nicht erzeugt {} };
-
Zu den warnings: ich hab mir jetzt nicht deinen ganzen Code durchsucht um die entsprechende Stelle zu finden, aber es sieht so aus, als haettest du die Initialisiererliste im Konstruktor andersrum geschrieben als die Deklaration der entsprechenden Variablen. Da aber in C++ immer in der reihenfolge initialisiert wird, wie die Variablen in der Deklaration stehen, wird die Initialisierungsliste in dem Fall nicht von vorn nach hinten abgearbeitet sondern etwas hin und hergesprungen. Am besten schreibt man daher die initliste genau in der Reihenfolge wie die Deklaration, damit nichts unerwartetes passiert.
-
Mh, also ich verstehes nicht so ganz, weil nur "struct" hat eine Initialisierungsliste, und in dieser steht doch alles in der richtigen Reihenfolge. Welche Stelle meint ihr den jetzt genau, sry ich stehe grad auf der Leitung. Und äh kann sich vll. noch jemand mein 2. Problem anschaun?
-
Dann schau noch mal ganz genau hin:
struct part { //... std::string m_question[3], m_a, m_b, m_c, m_effect[3]; //... const game *m_parent; }; //... game::part::part(/*...*/) : m_parent(parent_),m_a(a_),m_b(b_),m_c(c_)*hust* Oh, naja hast wohl Recht. Scheint alles in Ordnung zu sein. *hust*
Gruß
Don06
-
Oh, mh "game *m_parent" kommt erst zum schluss nä? ...Und was ist jetzt mit meinem 2. Problem...dem nicht Zeilenumbruch bei eingeschaltetem Vollbildmodus.