Jump to content
  • Advertisement

CoB_ChrizZz

Member
  • Content Count

    32
  • Joined

  • Last visited

Community Reputation

102 Neutral

About CoB_ChrizZz

  • Rank
    Member
  1. hello ! i am playing around with the wonderful cross platform library libgdx which i am using as supposed with java. In window mode everyhing works fiine. But as soon as i set it the program to fullscreen the game-loop seams to be still working (like input and such is being recognized) but i am having a full white screen. Even though i am assuming that a lot of the users here don't know libgdx i am hopingt that it might be a maybe more common opengl es based issue. anyone an idea ?
  2. okay, thank you Corntstalks.. I hope it is right now ^^ void deleteLoecher() { //Vorerst müssen alle einzelen dynamisch angelegten Pointer-MetallScheiben-Objekte aus loch entfernt werden for (int i = 0; i < anzahlLoecher; i++) { delete loch; } //Schlussendlich müssen wir noch den "pointer auf ein Feld von pointern" selbst köschen delete[] loch; }
  3. i am sorry i found my mistake..it's in the overloaded operator= method ...i copy some data of the newly assigned object in advance BEFORE i delete the old allocated memory. (One of it was an index variable) I "think" it should be right now ! ^^ @Cornstalks: Thank you for your reply. in line 66 i do this: loch[anzahlLoecher] = new MetallScheibe(lochRadius); so i am assigning memory to one of the indexes of loch[] which happens to be all pointers
  4. hi ! code: #include "stdafx.h" #include <iostream> using namespace std; //Klasse MetallScheibe class MetallScheibe { protected: static const double PI; //Wie initialisiert man eine Klassenvariable richtig ? double radius; public: MetallScheibe(double radius) { this->radius = radius; } double getRadius() const { return radius; } virtual double flaeche() //was macht das virtual ? { return PI * radius *radius; } bool isSchwererAls(MetallScheibe* ms) { return flaeche() > ms->flaeche(); } }; const double MetallScheibe::PI = 3.14152; //Klasse Sieb class Sieb : public MetallScheibe { private: int anzahlLoecher; int maxAnzahlLoecher; double lochRadius; MetallScheibe** loch; public: //Einen Konstruktor Sieb(double radius, int maxAnzahlLoecher) : MetallScheibe(radius) { this->maxAnzahlLoecher = maxAnzahlLoecher; loch = new MetallScheibe* [maxAnzahlLoecher]; this->lochRadius = radius/maxAnzahlLoecher; this->anzahlLoecher = 0; } void neuesLochStanzen() throw (out_of_range) //diese methode wirft eine out_of_range exception { if(anzahlLoecher + 1 > maxAnzahlLoecher) throw out_of_range("max Anzahl Loecher erreicht"); else { loch[anzahlLoecher] = new MetallScheibe(lochRadius); anzahlLoecher++; } } double flaeche() { return MetallScheibe::flaeche() - (anzahlLoecher * (PI * lochRadius * lochRadius)); } void deleteLoecher() { //Vorerst müssen alle einzelen dynamisch angelegten Pointer-MetallScheiben-Objekte aus loch entfernt werden for (int i = 0; i < anzahlLoecher; i++) { delete [] loch; } //Schlussendlich müssen wir noch den "pointer auf ein Feld von pointern" selbst köschen delete[] loch; } //Einen Destruktor, der den dynamisch angelegten Speicherplatz freigibt ~Sieb() { deleteLoecher(); } //Einen Kopierkonstruktor...Hier werden die Attribute dieses Objektes von einem anderen sieb überschrieben Sieb (const Sieb& sieb) : MetallScheibe(sieb.radius) // auch beim Kopierkonstruktor muss der Konstruktor der Basisklasse aufgerufen werden { if (this != &sieb) { anzahlLoecher = sieb.anzahlLoecher; maxAnzahlLoecher = sieb.maxAnzahlLoecher; lochRadius = sieb.radius/maxAnzahlLoecher; loch = new MetallScheibe*[maxAnzahlLoecher]; //auch alle Loecher des Siebes müssen kopiert werden ! for (int i = 0; i < sieb.anzahlLoecher; i++) { loch = new MetallScheibe(sieb.lochRadius); } } } //Einen überladenen Zuweisungsoperator Sieb& operator= (const Sieb& sieb) { if(this != &sieb) { anzahlLoecher = sieb.anzahlLoecher; maxAnzahlLoecher = sieb.maxAnzahlLoecher; lochRadius = sieb.radius/maxAnzahlLoecher; //im Gegensatz zum Kopierkonstruktor muss hier die //dynamisch erzeutgen MetallScheiben gelöscht werden, //da operator= auf bereits erzeugt und inizialisierte //objekte angewendet wird deleteLoecher(); //WHAT'S WRONG ??? loch = new MetallScheibe*[maxAnzahlLoecher]; for (int i = 0; i < sieb.anzahlLoecher; i++) { loch = new MetallScheibe(sieb.lochRadius); } } return *this; } }; //TODO: Globale Funktion lochen() Sieb& lochen(MetallScheibe ms, int maxAnzahl, int anzahlLoecher) throw (out_of_range) { if(anzahlLoecher+1 > maxAnzahl) { throw out_of_range("max Anzahl Löcher erreicht"); } else { Sieb* sieb = new Sieb(ms.getRadius(), maxAnzahl); for (int i; i < anzahlLoecher; i++) sieb->neuesLochStanzen(); return *sieb; } } int _tmain(int argc, _TCHAR* argv[]) { Sieb sieb(2.0f,3); sieb.neuesLochStanzen(); sieb.neuesLochStanzen(); cout << sieb.flaeche() << endl; Sieb sieb2(2.0f,4); sieb2 = sieb; cout << sieb2.flaeche() << endl; char f; cin >> f; return 0; } i am having problems using the destructor's "deleteLoecher" method in code line: 126 get an access violation and i guess it is because i am trying to delete memory that isn't dynamicly allocated. In line: 54 i am allocating an array of pointers to the variable "MetallScheibe** loch". In the class function "neuesLochStanzen" in line: 66 i "think" i am allocating memory for a new MetallScheibe() object. is there something wrong with my allocation ?</iostream>
  5. super, thank you Brother Bob. That cleared my whole confusion about this issue !!! and thanks to all the other guys again who basicly said the same but i misinterpreted the thing about the temporary variable ;)
  6. Thank you guys but i still have some uqestions ^^; The compiler creates automaticly a constructor with 20 as value AND then assigns 20 to it, which doesn't change anything at all ? I mean i would understand if the compiler would create a new instance of X with -1 as default parameter and then assign 20 to it. And what makes "a" temporary ? it doesn't run out of scope but is destroyed ? i never saw this beahaviour before. Does this depend on the c++ compiler i am using ? or is this a determined thing even before runtime ? sorry for my noobish question but i have an important test on friday and i really wanna understand things more in depth :/ thank you very much !
  7. Hi, i got trouble to understand the following call in the main(): a =20; class X { private: int data; public: ~X() { cout << "Destruktor " << data << '\n'; } X(int d = -1) : data(d) { cout << "Allgemeiner Konstruktor " << data << '\n'; } X(const X &x) : data(x.data) { cout << "Kopierkonstruktor " << data << '\n'; } X& operator=(const X& x) //nimmt auch Konstanten (wie in etwa 20) { data = x.data; cout << "Zuweisungsoperator " << data << '\n'; return *this; } void set(int d) { data = d; } int get() { return data; } }; X a(0); int main() { cout << '\n' << "Start main" << '\n'; X a; // Allgemeiner Konstruktor -1 a =20; // Allgemeiner Konstruktor 20 // Zuweisungsoperator 20 // Destruktor 20 char g; cin >> g; return 0; } basicly a = 20 should be an assignment by using the assignment operator. But it also works without the assignment operator. It would just print out: Allgemeiner Konstruktor 20 Destruktor 20 instead. So what happens here ? can't the compiler decide wether ist is an assignment or a constructor call ? why is this ? and why is there an destructor call ? it's definetely not because it reaches the end of the programm..because it still awaits "cin >> f"
  8. CoB_ChrizZz

    c-string fuction: insert

    thank you Adam_42 ! But i may only use the helper functions: strcpy(), strcat() and strlen() thanks about pointing out a memory leak (i will look after that later) and the issue at the end !
  9. i got this excercise: Implement an elementary function insert(), that inserts the part-string "s" from the index "start". If the index is too big or to small, nothing will happen. of course the manipulation demands a resizing of the String-Object void String::insert(int start, const String& s) { //my attempt: http://pastebin.com/7KUshGF3 } String is a selfmade class whose dynamicly allcoated variable i shall manipulate with this function is: char *str; It took me quite a while to implement this and i really doupt i will write this on paper (in time) in case it is part of my test on friday. I thought there must be a smarter way to do this. So i came here to ask for help once more ^^
  10. wow, thank you haeggar and Antheus. This was very helful so: next = list let's the next pointer still point to the las added "node" to the list and THEN the list points to the newly added object (which is the "next" of the next added node...and on and on ^^
  11. hello ! I just found this nice example. http://pastebin.com/4QV5k0ev Even though it works and i see the code in front of me i don't understand how this works. The output is: A::f 60 B::f 55 b2 B::f 44 b1 A::f 30 A::f 20 A::f 10 So it is the reversed order of the objects that have been created. code line 15 is where the "magic" happens. the list of A objects is static (so all created objects share the same list) but every time a object is created the next pointer points to the list, which points to " this" (the just created object)...so how i understand this is that the list-pointer is every time overwritten by the actual object coz the pointer is never incremented. -> A::f 60 and the next strange thing is the void A::printList() function in line 23. I don't get this at all ^^ Can somebody explain me how this works ?
  12. thank you very much Antheus !
  13. it says: Write a function ctob(), which converts a c-string (given as an argument) in a equal stringchain in byte.count-format there are also 2 pics like that: C - String: | S | t | r | i | n | g | \0 | Byte-Count-String: | 6 | S | t | r | i | n | g | @Antheus :t think so, too...the excecise isn't really usual but i have to deal with stufff like that...but i have still time till next friday. @swiftcoder: thank you for the deeper explenation !
  14. hmm..i tried it with "string" and i actually get "string" as output compined with a hardware-bleeping sound but not the numeric size value in front ^^ I am really depressed by a lot of the excercises that happens in test. Most tests are made that you can get through if you are just as fast as copying all the answers from a solution paper on a blank one...but that's another issue :/ thank you very much for your replys, see you later ! ;)
  15. hello ! i am still preparing for an c++ test and i am trying to convert a c-string to a byte-count-string. so if i have a string like: "Hello" I have to convert it to: "5Hello" However the problem i am facing is that i can't convert the calculated count of the string to an char value. it should be very straight forward since this excercise gives only very little points in the test #include "stdafx.h" #include "iostream"; using namespace std; char* c2b(char* bc) { int b = strlen(bc) +1; char* temp = new char; int i; for(i = 1; i < b; i++) temp = bc[i-1]; b -= 1; char test = static_cast<char>(b); //I want to cast the Integer to a char temp[0] = test; //temp = '\0'; //Not needed for the Byte-Count-String bc = temp; return bc; } int _tmain(int argc, _TCHAR* argv[]) { char bc[] = "String"; cout << c2b(bc); char f; cin >> f; return 0; }
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!