• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

154 Neutral

About elementary

  • Rank
  1. Total Begginer C++ Tutorial

    Quote:Original post by Washu Quote:Original post by NoWhereMan Quote:Original post by Eriond To use string, include string :) You didn't do that in your example. Are you taking about #include <string>? That's not necessary here, all you need to do is: *** Source Snippet Removed *** It works just fine, and this tutorial is intended for complete beginers. It is necessary. If you are going to write a tutorial for complete beginners, make sure it is completely correct so that they don't get completely weird errors with their completely incorrect code. But hey! Atleast you're trying. Just make sure your information is correct before publishing it, and all will be well. The guy obviously hasn't got a clue what he's talking about, and shouldn't be writing tutorials. blind leading the blind.
  2. My first game

    I disagree, your code has some bad errors. Firstly and most obviously, your array accesses are incorrect. char board[9]; The above statement declares a 9 element array, the first element is board[0], the last element is board[8], not board[9]. This means your loops are incorrect, and your function which checks for three in a row is also incorrect. You are overwriting the array bounds, and corrupting the stack. Change your loops from i <= 9 to i < 9. Other things to note are the i % 3, a comment there might be helpful, not totally obvious what is happening there to a lot of people. the stdlib.h header file is also deprecated in C++, it has been replaced with the cstdlib header. using namespace std; is generally not good practice in larger projects, something to be aware of. system("PAUSE"); is not a portable command. Other than that.. well done :)
  3. C++ - 2 unrelated questions

    I agree with Petewood, I think Modern C++ Design has some clever tricks, but a lot of the book will be lost on you if you havn't read Desgin Patterns. You can look at Modern C++ Design as a book on providing generic implementations in C++ of some of the patterns covered by the Design Patterns book. It has some clever tricks, but depending on your level of C++, a lot of it might be over your head. I think Design Patterns is a must read for every developer.
  4. Global Variables in C++ 6

    Sorry, cant help. I only know C++ 5.
  5. Two dimesional vector array

    CVector3 (*PolyMap)[2] = new CVector3[1023*1023][2]; delete [] PolyMap; Also consider boost::multi_array and std::vector.
  6. basic templates stuff

    Its best to put it in, though you may try a preprocessor substitution (#define). The typedef will not work.
  7. C++: protected - confused

    Except friends classes/functions.
  8. #ifndef/#define or #pragma once?

    I just made a macro to generate the random header guards in 2003.net, makes life pretty simple.
  9. The std::sprintf in the <cstdio> header is not deprecated. Enjoy!
  10. Which should also be followed by an explicit call to its destructor class->~MyClass();
  11. C++ Problem.

    mmmm.. cake.
  12. C++ Problem.

    "A fridge!" shrieked the oracle in triumph.
  13. C++ Problem.

    Quote:Original post by mrmrcoleman Whats goes black, white, black, white, black, white? Riddle me this, riddle me that [HINT: its not Michael Jackson]
  14. Templates

    I use them in my own code, they are frowned upon a little at work. Probably because 90% of the code cycle is maintaining the code, and it is expensive to train people in all the details of template meta-programming and template instantiation and overload rules. I can't say i have ever missed them at work. Instead, for example, of using a generic matrix class at work, we simply use a class that is hardcoded for float, how often do you use anything other than float in a matrix class? Not very. Instead of using a dot product meta-program to unroll the loop of dot product, its done by hand. The argument has also been put at work that they can bloat code with hidden instantiations, though if used properly with a good compiler, that can be reduced a lot. The trouble is the 'used properly' bit, that requires training people to use them properly, which requires time and effort. Templates do have a lot of powerful uses though, and if the case arose where templates would make the code a lot more maintainable, then I don't think anyone could blame anyone at work for using them. Personally, I am trying to cut down on the amount that I use templates now, if you are not careful you can end up with every function being a template, and all your code in header files, and 90% of the time it is completely pointless in it being like that. Tons of template instantiations can also increase compile time dependencies and compilation time, which can be harmful to productivity.
  15. integer to string

    Which language? itoa() is not a valid C or C++ function. At a guess the function prototype is itoa(int number, //the number you want as a string char* string, //the string you want the number to be put in int radix) //the radix of the number in the string But as i say, that is not a portable function in C or C++. Stringstreams provide an alternative in C++. #include<sstream> std::stringstream ss; ss << myint; std::string mystringnumber = ss.str(); You could also use boost::lexical_cast in C++. EDIT: Corrected 3rd param
  • Advertisement