2,898 Posted Topics
Re: Well, Boost.Thread has the future / promise mechanism, that's where it was taken from. What std::async accomplished under-the-hood to run a thread with the given callable and attaches a future to it is quite simple, at least for the non-deferred launch version. The deferred version is also quite simple to … | |
Re: Indeed, pretty much all modern operating systems have good mechanisms to deal with memory and use the hard-drive if necessary. Of course, there will always be a chance that you run out of memory (whether the OS doesn't want to take up more HDD memory or because you run out … | |
Re: Well, from the code you posted, if there is no [ICODE]delete a;[/ICODE] after, then there is clearly a memory leak there. How I found that memory leak: I opened my eyes and looked, that's a good trick. Seriously though, finding memory leaks can be a very difficult if you have … | |
Re: Once you understand the idea that the purpose of a programming language is to act as an interface between a human being and a computer, then it becomes pretty clear why goto statements are bad. A guy that is trained to write assembly code might have a brain that is … | |
Re: At line 103, you should have [ICODE]elements_= new T[rhs.size];[/ICODE] (notice "int" changed to "T"). In you copy-constructor, it is not a good idea to name the parameter [ICODE]copy[/ICODE] because there will be a name conflict with [ICODE]std::copy[/ICODE] that is used in the same function. And you should qualify the call … | |
Re: Well, I guess I should answer this, considering that path-planning is the subject of my Ph.D. thesis (the scenario is quite a bit more complex, of course). Storage: What you refer to as a "navigation mesh" is essentially a graph (a network of nodes and edges that link them together). … | |
Re: >>Can you please tell me what is meant by forward declaration? A forward-declaration is just a way to tell the compiler that there will eventually be a class declared later in the code. It is only a means to stop the compiler from complaining that it doesn't recognize the type … | |
Re: Pretty much everything that you find documented at [URL="http://www.cplusplus.com/reference/"]www.cplusplus.com/reference[/URL], that's most likely what the competition will want you to stick with. If anything, they might allow the new (extended) set of standard libraries from the C++11 standard, which you will find described and listed in the draft that deceptikon linked … | |
Re: It's actually simpler than you think (for once!). To do a partial template specialization in C++ you simply leave the unspecified template arguments in the template declaration and put them in the class name... well, that sounds weird, so let me just put it in code: [CODE] // This class-template … | |
Re: Interesting question, it warrants a detailed response. So, let me address some issues before providing more concrete solutions. >>I have started finding lots of uses for abstract classes to define interfaces for common functionality using polymorphism RED FLAG!! Maybe you misspoke, because otherwise you are hinting at a very common … | |
Re: Yeah, that's pretty much it. Try this for instance: [CODE] #include <pthread.h> #include <iostream> void* f(void*) { for(int i = 0; i < 1000; ++i) { std::cout << "Print from the Thread!" << std::endl; usleep(1000); }; return NULL; }; int main() { pthread_t threadID; pthread_create(&threadID, NULL, f, NULL); for(int i … | |
Re: I think enough time and ink has been spent on this already, so let me lay out a clearer, step-by-step explanation of this circular-queue implementation. You have to first examine what you need those "rear" and "front" indices for. The rear index is used to find the next available free … | |
Re: I believe that the difference is that Windows actually makes a difference between programs that run as a console application (MSDOS) and programs that run in the Windows system (Win32). If you try to run a program that uses WinMain() from a console window, you will probably get the message … ![]() | |
Re: Your function and its output are correct. If you consider the interval to be inclusive [start, end], then inverting the sequence [1,4] should produce the output AEDCB (because 4 is the last element). If you consider the interval to be non-inclusive of the end-point, as in [start,end), then you should … | |
Re: For GUI programming, it is pretty much as easy to do it in C++ as with any other language, it is not a matter of the language but of the GUI library (or package) that you use. For a long time, under Windows, main-stream GUI programming was with MFC which … | |
Re: If you use the [URL="http://www.boost.org/doc/libs/1_48_0/doc/html/boost_random/reference.html#boost_random.reference.generators"]Boost.Random[/URL] library, there are plenty of different random number generators with all sorts of cycle lengths (including 2300000 bits). The new C++ standard (C++11) also includes a [URL="http://en.cppreference.com/w/cpp/numeric/random"]random library[/URL] with a lot of the generators from the Boost.Random library, but you need a fairly recent compiler … | |
Re: The destructor also doesn't delete the pcMyString data, that's a memory leak. The reverseString() function is marked "const" when it is clearly (from its name) a function that would modify the contained string. The pointer "poMyOld" is public and uninitialized. It is generally bad to expose a pointer as public … | |
Re: Quicksort is not really the most popular algorithm for sorting. The most popular algorithm for sorting is whatever sorting function your programming language's standard library provides, that is, if you consider "popular" as what most people use. In C++, we use the std::sort() algorithm (and other sorting-related STL algorithms). And … | |
Re: Start small and move on. For example, you can start by writing a text-based RPG. Then, learn to use simple GUI systems like SDL to create 2D games, a good start could be a Nibbles game or Tetris. Finally, you can start to look at creating 3D games, I suggest … | |
Re: The main problem you will have with STL's priority-queue is not the efficiency, but the fact that it provides no means to update the priority value of elements already in the queue. This is an operation that is required in A* (at least, the last time I checked). If you … | |
Re: >>But I am not able to figure out from those discussions. That's probably because of two reasons that make this question a bit hard to answer. Before getting into it, of course, the two standard options that are available are C standard functions (i.e. fread() and fwrite(), or fscanf() and … | |
Re: >>Do you mean if i were to declare an object with dynamic memory within a particular function it would be available within another function? Yes, if you provide the pointer as a result of the function for example. Generally, this is not recommended, but sometimes hard to avoid. If you … | |
Re: One of the main reasons why autocomplete features are generally lacking in enhanced text editors (like Emacs or Kate) is that it requires some knowledge of the build configuration (source files included in the build, include paths, environment variables and such things). So, the bare minimum that you are going … | |
Re: When you have syntax like [ICODE]g->total_nodes[/ICODE] it means that you access the object pointed to by "g" and then access its data member called [ICODE]total_nodes[/ICODE]. When you write it as [ICODE]g.total_nodes[/ICODE] it means that you access the data member called [ICODE]total_nodes[/ICODE] that belongs to the object "g". So, if you … | |
Re: As thines01 points out, but more precisely, what you really seem to be trying to do is to create a Domain Specific Embedded Language (or DSEL for short). This can be done directly in C++, to a large extent. However, it is far from easy. Generally, it involves a heavy … | |
Re: Line 15 is an implicit conversion operator. The return type is [ICODE]const ANew*[/ICODE], and so, you need to return that. As in: [CODE] operator const ANew* () const { return this; } [/CODE] But I have to say that I don't approve of this implicit conversion from value to pointer, … | |
Re: [URL="http://en.wikipedia.org/wiki/C_(programming_language)"]C[/URL] is generally considered as a low-level to mid-level, functional programming language which moderately enforces an explicit and static type system. It provides native syntactic support for [URL="http://en.wikipedia.org/wiki/Structured_programming"]structured[/URL] and [URL="http://en.wikipedia.org/wiki/Procedural_programming"]procedural[/URL] programming paradigms. [URL="http://en.wikipedia.org/wiki/C%2B%2B"]C++[/URL] is generally considered as a general-purpose (low- to high-level), multi-paradigm programming language which strongly enforces an explicit … | |
Re: The difference is purely semantics (and type-related), but that doesn't make the distinction a trivial one. Just like in English, we mean different things when we say "nothing", "no-one", or "nowhere", which correspond, analogously, in C++ to [ICODE]0[/ICODE], [ICODE]'\0'[/ICODE], and [ICODE]NULL[/ICODE] (which was actually replaced by [ICODE]nullptr[/ICODE] now). Just like … | |
Re: You need to show efforts of your own before you can hope to get help on specific problems you encounter while doing this assignment. We don't just do your homework for you, because that would not help you or anyone else. | |
Re: You need [URL="http://en.wikipedia.org/wiki/Include_guard"]header-guards[/URL]. Simply do this for your header file: [CODE] #ifndef MY_COMPLEX_HEADER #define MY_COMPLEX_HEADER #include <iostream> using namespace std; class Complex { public: Complex(); Complex(double, double); Complex operator+(Complex); Complex operator-(Complex); Complex operator*(Complex); bool operator==(Complex); bool operator!=(Complex); friend ostream &operator<<(ostream &, Complex &); friend istream &operator>>(istream &, Complex &); private: … | |
Re: If you call g++ with [ICODE]-std=c99[/ICODE] or any type of C standard specification, you must be compiling C code. It doesn't matter that the compiler is called "g++", if you tell it to compile C code, it will expect C code and only accept that. The problem here is that … | |
Re: Most examples that you posted were indeed bad style, wrong and/or inefficient. As for the weirdness of it, generally, straight-out weirdness usually originates from Frankenstein code, meaning that the code is often the result of piecing together inharmonious codes and/or the result of trial-and-error where a previous version used to … | |
Re: That is obviously a return value optimization, I mean, it's a textbook example of NRVO. That's what you would expect any half-decent compiler to do. I don't understand your question about the "limit" of NRVO. If you mean, how complex a situation can the compiler cope with, then I would … | |
Re: Depending on the way that the DLL was compiled, it might be possible for you to use it from a VS2008 project. The easiest solution, of course, is to contact the issuer of the library in question and ask for a VisualC++ import library (or the source code so that … | |
Re: There are some limits to what you can do with a forward-declared type. In technical terms, a type that was forward-declared but not yet declared (the compiler has not reached the full declaration yet) is called an "incomplete type". The reason for that name is simple, the compiler doesn't have … | |
Re: If you run this with any kind of optimization (or even the base level), it will optimize the entire operations away, making it equivalent to [ICODE]number = 0xFFE0;[/ICODE]. You need to make the number change at run-time and you need to do the operation a lot of times too, maybe … | |
Re: You cannot separate the compilation of the function template from its declaration. Function templates are only compiled when they are used with a specific template argument, we call that instantiation. Your implementation of the function is never compiled in the cpp file because it is not used when you compile … | |
Re: Of course, you can use malloc() but you have to be aware that it doesn't call the constructor, so, you have to do that yourself directly afterwards, through a placement-new operator. The "initialize" function that you posted: [CODE] //create and initialize void* initialize() { MessageQueryTester* self = (MessageQueryTester*)malloc(sizeof(MessageQueryTester)); memset(self, 0, … | |
Re: You should just run your program in [URL="http://valgrind.org/"]Valgrind[/URL] and see the report afterwards about if there are any memory leaks. Or, use any other memory debugging tool. Basically, memory leaks are a consequence of heap-allocated memory (or freestore in general) that is not freed (and is then forgotten, made unreachable), … | |
Re: I guess so, broadly speaking. However, a game engine would usually be more generic, as opposed to specific. I would be reluctant to say that any computer game is also a game engine. Like a car engine, you provide the decorations (exterior and interior) and the engine drives it. I … | |
Re: You're trying to mix a compile-time mechanism (overloading) and a run-time mechanism (dynamic dispatching). They can't mix (at least, not that way). You have to choose. You can achieve run-time dispatching based on the type, that is dynamic dispatching. The native mechanism for doing that is the use of virtual … | |
Re: Shouldn't the Patch class hold a pointer to the image to which it is a patch of? It would make a lot more sense if you had the Patch class to act as a [I][URL="http://www.gnu.org/software/gsl/manual/html_node/Matrix-views.html"]view[/URL][/I] of the image. What is a Patch if it is not a sub-image? If the … | |
Re: Wow, this is a bit messy, to say the least. Your problem is with the mixed responsibilities more than any other issue (templates, non-templates, base-classes, etc., these are all just details). From my understanding, the overall purpose is to perform transformations which are characterised by the following: - Input - … | |
Re: >>Is there any reason you would want to write your own RTTI system for use in your code, when there already is one in C++? Empirically, there most by since there are a number of libraries that rely on some form of a custom RTTI (some build upon the C++ … | |
Re: With compilers in general, we often talk about the front-end and the back-end. The front-end is the program that parses the source code, verifies all the grammar and syntax rules, and basically produces a translation of it in some intermediate language (not human-readable but readable for the back-end). The back-end … | |
Re: >>i can say for sure that it will work with internet That's pretty vague. Surely, for internet-related programming, C/C++ aren't good choices. Although I am of the opinion that no education in programming is complete without being at least functional in C++ programming (because it is so central to the … | |
Re: There are a number of things happening here that make this test flawed. Generally when people make performance arguments between static versus dynamic polymorphism (i.e. based on templates or based on virtual functions, respectively), the thing that makes all the difference is whether the mechanism is static or dynamic. So, … | |
Re: Is it really that hard to google "[URL="https://www.google.com/search?client=ubuntu&channel=fs&q=calling+convention&ie=utf-8&oe=utf-8"]calling convention[/URL]"? The first three links gives all the info you are looking for. | |
Re: So, there is only a very trivial difference between a [ICODE]struct[/ICODE] and a [ICODE]class[/ICODE]. And [ICODE]struct[/ICODE] was kept for backward compatibility with C, while [ICODE]class[/ICODE] was introduced because it is generally more appropriate for Object-Oriented Programming purely on the basis of vocabulary (i.e. in OOP with about "classes" of objects) … | |
Re: >>However, I guess I don't understand why the object that was getting passed was const? My guess is that the STL implementation of std::sort wraps the "compare" object inside another functor that takes either const-references or const-iterators. So, the only viable options when defining a comparison functor is to use … |
The End.