2,898 Posted Topics
Re: Declaring the variable as [`volatile`](http://en.wikipedia.org/wiki/Volatile_variable) might help. | |
Re: >My professor asked me to search why this is happening "searching" and "asking" is not the same thing. If he wants you to investigate the matter, then you should investigate the matter, not just ask someone else for the answer. | |
Re: Let me elaborate: 1. Boot with a live or rescue CD/DVD/USB drive. I think this is pretty straight forward, you find Live-CD from any distribution of Linux (or install CD), and when you boot from it, you don't go through installation (if available) but instead boot from the CD. 1. … | |
Re: If you can't get to grub, then you can't boot in terminal or start a terminal because the operating system has not started yet. The bootloader is the small program that executes in order to start the operating system. If that program cannot start the operating system, then there is … | |
Re: If you have "learned" all those basic stuff that you listed, then it might be a good time to go through the [FAQ Lite by Marshall Cline](http://www.parashift.com/c++-faq-lite/) to fill in any holes that might remain (the devil is in the details) and to learn a number of basic coding guidelines. … | |
Re: For the actual theory, this [SO thread](http://stackoverflow.com/questions/5243983/what-is-the-most-efficient-way-to-implement-a-convolution-filter-within-a-pixel) is a good starting point. Convolutions are never actually calculated like it appears in theoretical equations. As the SO thread says, you either perform the multiplication in Fourier space (instead of a convolution in the original space), or you separate the filter in … | |
Re: If you mean that you want to call the constructor from the body of that constructor, recursively. That's possible (with the syntax rubberman showed). However, it is nasty and useless because if you want to create your object through some recursive process, then you can easily put that recursive process … | |
Re: Forgive AD, he's getting a bit senile ;) From your last thread, you do know how to swap two nodes that are next to each other, right? Well, you should, because I told you how. The problem with swapping two adjacent nodes is that you also needed to keep track … | |
Re: You don't need to load a new texture, nor do you need to generate new texture objects (the `glGenTextures` call). When SOIL loads the image and puts it into an OpenGL texture object `texture[0]`, you then bind it and use it when rendering vertices. If you want to reuse it … | |
Re: This is a huge topic and you will have to think it through much more than that to make it out alive (figuratively). What you want is a game engine. Either make your own simple design or pick one off-the-shelf. If you want suggestions for an off-the-shelf option, I would … | |
Re: Don't use recursion when you expect a linear recursion depth (or more). In your code, for an array of size N, your recursive function will eventually be called N times. When you use recursion, in the real world, you have to be vigilant about the depth of the recursion because … | |
Re: You cannot directly link to a DLL like that, as the error says. To link to a DLL, you can do it either statically or dynamically. Statically, you need an "import library" (or "interface library"). This is a .lib file that acts as an intermediate between the linker of the … | |
Re: I hope nobody asks you to sort 1000 values! Ever heard of the concept of [scalability](http://en.wikipedia.org/wiki/Scalability)? Ever heard of [arrays](http://en.wikipedia.org/wiki/Array_data_structure)? Ever heard of [sorting algorithms](http://en.wikipedia.org/wiki/Sorting_algorithm)? | |
Re: To swap two nodes of a single linked-list you will have to keep track of three pointers, let's call them "previous", "candidate1" and "candidate2". These three should always appear in that order in the list, that is, "previous" is the node before the first candidate for swapping and "candidate1" and … | |
Re: That syntax is the [initialization list](http://www.parashift.com/c++-faq/ctors.html#faq-10.6). The initialization list is for all sub-objects (which includes both base-class instances and data members) of an object. It is simply a comma-separated list of constructor calls for each base-class instance and data member belonging to a class. In your specific example, `value` is … | |
Re: EDIT: sorry double-post. | |
Re: Are you kidding me? You have written `~Node(){delete this;};`. This is wrong on so many levels. You should not do this, you don't need to do this, and it will most probably crash your program when you run this. You have to consider the "this" pointer as a constant, in … | |
Since the overhaul, there are some nice feature of the old system that are missing in the thread titles. By thread titles, I mean as they show up in the forum listings (the icon (new, read, etc.), title, # of replies, time of last post, etc.). Some of the features … | |
Re: Because the object is passed by value to the area function, meaning that another, temporary rectangle object is created and passed to the area function. When the area function is done, that temporary is destroyed. Afterwards, when the main function ends, the obj is destroyed. Try changing the area function … | |
Re: Don't even bother trying to give a circumvented explanation on the legitimacy of your purposes for this type of code. You're not talking to idiots who were born yesterday, don't insult our intelligence. | |
Re: The edit button seems to require a number of page refreshing and/or leaving and coming back to the thread. Also, I have no idea what you intended to initially write in your d.mkv example. You should refer to [this page](http://daringfireball.net/projects/markdown/syntax) about the syntax rules. I think what you are looking … | |
Re: Or maybe: int main() { return 0; // 0 is an object and it doesn't have a name. }; | |
Re: Your algorithm is called "[URL="http://en.wikipedia.org/wiki/Selection_sort"]Selection Sort[/URL]". And no, it is not similar to heap sort. It is true that heap sort has a second phase where the max (or min) elements are extracted from the unsorted section and stacked at the beginning or end of the overall array. However, the … | |
Re: Because data members that are in the [ICODE]private[/ICODE] scope are only accessible from the class in which they are declared (or a friend), but not in derived classes. You must use the [ICODE]protected[/ICODE] scope to make the data members of the base class accessible to the derived classes. In other … | |
Re: It's nice to read all the different stories. I find that the common denominator is ".. and I never looked back.". My field is robotics (mostly mechanical engineering) and so Linux is a very common OS for all sorts of robots and related research activities. I first got introduced to … | |
Re: If you are going to create a function template to sort an array, I would recommend that you follow the same signature as the std::sort function. The problem with your function template is that it is not generic enough, it only applies to a C-style array of types which can … | |
Re: Easy, you just return a reference from the indexing operator. Here's what I mean: [CODE] class int_array { private: int arr[10]; public: // element accessor: int operator[](int i) const { return arr[i]; }; // element mutator: int& operator[](int i) { return arr[i]; }; }; [/CODE] And that's it, same for … | |
Re: Well, one way to do this is with a friend function: [CODE] #ifndef TEMPLATES_H_INCLUDED #define TEMPLATES_H_INCLUDED #include <iostream> #include <vector> using namespace std; template <typename T> class CustomType { private: vector<T> TypeData; void Insert() {} template<typename A, typename... Args> CustomType& Insert(A FirstArg, const Args... RemainingArgs) { this->TypeData.push_back(FirstArg); Insert(RemainingArgs...); return *this; … | |
Re: [URL="http://en.wikipedia.org/wiki/Machine_learning"]Machine Learning[/URL] is the field of AI that studies this. An AI agent that learns from past mistakes and successes is in the branch called [URL="http://en.wikipedia.org/wiki/Reinforcement_learning"]reinforcement learning[/URL]. There are many approaches to this problem. Most notably, you have [URL="http://en.wikipedia.org/wiki/Q_learning"]Q-learning algorithms[/URL], and [URL="http://en.wikipedia.org/wiki/Genetic_algorithm"]Genetic algorithms[/URL] (or evolutionary algorithms). The algorithms themselves are … | |
Re: The reason why the code that you posted doesn't work is because the champ_type string that you obtain from the user and the one that is inside the object "obj" are not the same. The one you obtain from the user is a local variable in the main() function, which … | |
Re: No, don't use goto for such a simple purpose. If nothing more, it's better to replace it with [ICODE]while(true) { };[/ICODE] loop (and a [ICODE]break;[/ICODE] statement somewhere in the loop). At the least, this makes it clear that the code is a loop, and respect indentation rules, that alone is … | |
Re: First of all, yes, you are correct in that [ICODE]Foo * myFoo = new Foo();[/ICODE] must be freed with [ICODE]delete mFoo;[/ICODE]. The main problem that I see with your code is the way you handle the values stored in the nodes of your tree. Basically, the values are given to … | |
Re: >> The PrintValue function had to go to the .cpp file. If you mark the functions with the keyword [ICODE]inline[/ICODE], then you won't have to put the definition in the cpp file (if you don't want to). | |
Re: Have you learned about [ICODE]struct[/ICODE]? If you did, you should define a struct to hold all the data in once record, as in: [CODE] struct Individual { char first_name[80]; char last_name[80]; char city_name[80]; }; [/CODE] The kind of multi-level sorting that you are describing (sort by city, sort by last-name … | |
Re: >> When do I really need to use Delete in Destructors? When your class is responsible for allocating the memory that a pointer points to, then it is also responsible for deallocating that memory. This is what is referred to as [URL="http://www.daniweb.com/software-development/cpp/tutorials/378692"]ownership[/URL]. If your class creates a dynamic array, or … | |
Re: >> Am I stealing if I translate it? Technically, yes. Kind of hard to prove though, if you do a reasonable job of changing names and syntax. Of course, assuming the algorithm's definition is public domain (appears in a text-book or scientific publication), it's OK to make your own implementation … | |
Re: The post-increment operator ++ will increment the variable by 1 and return the value of the variable _before_ the increment. In other words, the operation is semantically equivalent to: [CODE] int post_increment(int& i) { int result = i; //record the value of the variable _before_ incrementing it. i = i … | |
Re: So.. what's the compilation error message? At what line? I would probably try to pass in a function pointer instead, since "gset" is an array of function pointers, maybe try to define the "compute" function as: [CODE] double compute(double (*f)(double x), double i) [/CODE] The rest can remain unchanged. Also, … | |
Re: I would guess the error comes from line 77-78 which reads: [CODE] return !temp1; return VIP = false; [/CODE] which will, of course, never set VIP to false since the function returns before that line. Also, you should update the setBal() function such that it also checks for a negative … | |
Re: First of all, you cannot create an array whose size is not fixed at compile-time. So, your array "size" cannot be a static array of size "n", you need a dynamic array. In C++, the preferred way to create a dynamic array is to use a standard class called "vector". … | |
Re: The standard reference site is: [URL="http://www.cplusplus.com/reference/"]www.cplusplus.com/reference[/URL] A wiki site also exists: [URL="http://en.cppreference.com/w/cpp"]http://en.cppreference.com/w/cpp[/URL] Otherwise, look to the C++ standard document (latest draft before ISO standard): [URL="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf"]n3242[/URL] Another good reference is the [URL="http://www.parashift.com/c++-faq-lite/"]FAQ lite[/URL]. You can also find several example codes [URL="http://programmingexamples.net/wiki/CPP"]here[/URL]. | |
Re: Making shadows in OpenGL (or DirectX) is not a trivial task. I'm not surprised that you would have trouble with the NeHe tutorial on the subject. The important thing to understand is that, in order to determine the shadows that the objects will cast, you need to render the scene … | |
Re: The problem is that you are not doing a deep copy of your object. Your assignment operator performs a shallow copy (copy only the pointer, you don't copy the memory it points to). I suggest you read my tutorial on [URL="http://www.daniweb.com/software-development/cpp/tutorials/373787"]resource-holding classes and RAII[/URL]. Your copy-constructor is also wrong, I … | |
Re: >> 1. How do I check the Template's parameter type? Using typeid is one way to do it, but a rather unusual one. It is more common to use one of the multiple type-traits that are provided by the [ICODE]<type_traits>[/ICODE] library (C++11 only), and/or the ones provided by [URL="http://www.boost.org/doc/libs/1_49_0/libs/type_traits/doc/html/index.html"]Boost.TypeTraits[/URL]. As … | |
Re: If Unity is the only problem, install another distro that is based on ubuntu, I recommend Kubuntu. Xubuntu seems popular too, or Mint. To get the best drivers, the easiest is just to make sure you have the latest version of a distro (and kernel). For the interface or desktop … | |
Re: I understand what you mean, the Unity desktop is weird to say the least. Have you considered a sister distro. I recommend Kubuntu 11.10 (which has [URL="http://www.kde.org/workspaces/plasmadesktop/"]KDE[/URL] as a desktop environment). I always liked it better than Ubuntu, maybe you will too. The plasma desktop is very customizable (you can … | |
Re: If you are using an IDE to do your programming, then most decent IDEs have a debugger included in them. The basic way to use a debugger is to set a break-point (a point in the code at which the execution will be suspended). Then, you run the program until … | |
Re: You're question is, by itself, a good topic for a software project. You exposed a problem that I cannot solve, maybe you can create an algorithm that solves that problem. The task you have bestowed unto us is this: Input: No information whatsoever about your interests or skills! Required output: … | |
Re: First things' first, to a large extent, classes in the C++ standard libraries (with the exception of iostreams) are not object-oriented classes, they are not meant to be derived from and they generally don't derive from other base classes from which you could also derive. The iostream library is an … | |
Re: There are a few possibilities: The [B]ugly[/B] way: Use [URL="http://en.wikipedia.org/wiki/Variadic_function#Variadic_functions_in_C.2C_Objective-C.2C_C.2B.2B.2C_and_D"]variadic functions[/URL] from C. This is what you were referring to with the "va_list". You should know that the first argument does not have to be the count of arguments, it could be anything, but C variadic functions don't give you … |
The End.