2,898 Posted Topics
Re: And, you should make the base-class desctructor virtual, as so: class Digitize { protected: int * number; int Digits; public: Digitize(_uint64); virtual ~Digitize() {delete [] number;} // notice the 'virtual' here. void Display(); }; | |
Re: I think you need a little lesson in common practices and idiomatic C++ programming. > In the first class with vectors, it returns the member array and it is read only to prevent resizing. Thing is, I want to be able to modify the values in it without the SetMemberValue … | |
Re: Is this, and all your other threads, entries to the code snippet contest? | |
Re: Thank you for your kind words! This is really what DW is all about, a cycle of helping, teaching, learning, personal growth and (virtual) friendships. Cheers! | |
Re: The two problems I see (besides the lack of indentation ;) ) is that you don't initialize the value of `count` and you have one too many iterations. A more correct code would be this: bigNum = 1; count = 0; while(count++ < power) bigNum *= num; Or, even better, … | |
Re: Yay for me (it would have been nay a month ago, now I have grown to like it), but I like the toggle idea. | |
Re: > Which is the best to use? It really depends on the case. Explanation below. > If I use const T&, will it create temporaries every single time? No. The whole point of it is that it won't create any temporaries. However, it will cause indirection, meaning that it is … | |
Re: > I do R & D in the world of Metaphysics, and my specialised subject is Subtle Energies. LOL! First time I hear about *Research* and *Development* in a branch of philosophy, let alone a non-empirical branch of philosophy. As for subtle energies, I bet they're subtle all right. If … | |
Re: A wrapper class is a fairly broad concept. It basically means to repackage a piece of code into a new interface (or coating). That I can think of right now, there are two main reasons for doing a wrapper class: adapting an interface, and decoupling the implementation from the interface … | |
Re: It depends what you mean by "share". If you just mean to "distribute" it, then that's just a matter of compiling your program in release mode (after being completely finished with it), packaging it in an installer, and distributing it (for free or for cash). If you mean sharing code … | |
Re: Isn't *any* code written in FORTRAN horrible? But this one is particularly horrible, probably the highest density of `GO TO` ever seen in one piece of code (excluding assembly code, of course). | |
Re: If you want better precision, you have to care about round-off error accumulation and amplification factors. Generally, things like subtracting numbers that are very close, or dividing number of wildly different magnitudes tend to make the round-off errors blow out of proportion. So, you can't really apply the mathematical formula … | |
Re: I think that at that age, if the kid wants to learn something, he'll learn it regardless of how hard it is. If he doesn't want to learn it, it won't matter much how easy it is. That's just the kind of curiosity and passion that kids have at that … | |
Re: That would definitely be useful, it did happen to me quite a few times that I lost a fairly lengthy post because of a temporary loss of internet connection or by accidentally navigating away from the thread's page. It would be nice if there was an automatic draft saving, and … | |
Re: Don't panic, relax, all is well. What that tutorial is refering to is the difference between *value-initialization*, *default-initialization*, and *zero-initialization*. These are a set of rules that the compiler follows to initialize objects in different "construction from nothing" cases. Basically, value-initialization and zero-initialization are the same, they set everything to … | |
Re: The difference between code 1 and 2 is that the code 2 is erroneous. malloc() allocates memory of the given size and returns a pointer to that memory. If you allocate memory big enough to store one `struct node` then you would store the pointer in a `struct node*` pointer, … | |
Re: > if i m not wrong it means , i have to create a reverse link list and then read it , in order to read a link list in backward fashion No. You understood AD and pyTony correctly (I think), that's what they suggested. But that is certainly not … | |
Re: The result type of the function should be changed: template <class T> MinMaxVector<T>& MinMaxVector<T>::push_back(const T &d) { v[sp++]=d; return *this; } | |
Re: Your question makes very little sense to me. What do you mean by "trying to get mangling for variable .."? Name mangling is not something that you should ever be able to see from within the code, because it is a feature used for linking (happens after compilation). Name mangling … | |
Re: > is there ever a time when you would not want to define all three destructors as virtual? Yes and no. Inheritance is mostly used in two contexts: for dynamic polymorphism in object-oriented programming; and for a number of template-heavy techniques in generic programming and template meta-programming. In the former … | |
Re: > What if I want to go from `char*` to `BYTE*`? I'd use reinterpret_cast right? Yes and no at the same time. The `reinterpret_cast` is, generally, to be avoided because almost anything you do with it is "undefined behavior", except for this one case you pointed out. When casting pointers … | |
Re: First of all, if the idea of the Parser function is to fill the vector of words contained in Lexical, then I see no point in returning that vector of words from the function. As for the overloading problem, I would recommend just going with the `std::istream` idea. The standard … | |
Re: > I would recommend that moderators get more involved with their members, not only in answering questions, but also in the voting and commenting process. I totally agree. I think, also, that it's important to be on the look-out for fairly new members that give good answers and encourage that … | |
Re: I have never tried this, but I believe that you can use this Wake-On-LAN feature that most ethernet cards have (unless it is really old, or bad). You can follow [these instructions](http://ubuntuforums.org/showthread.php?t=234588) (they are a bit old, but should still work). You can install the package `wakeonlan` on your remote … | |
Re: // Selection sort. // 'a' : A pointer to the first entry of the array of numbers to sort. // 'n' : The number of entries in the array. void selection_sort (int *a, int n) { int i, j, m, t; // For all positions 'i' in the array, for … | |
Re: When it comes to corrupt pointers (as in, pointer that hold a non-NULL address, but the address points no-where (a freed memory, or otherwise)), there really isn't any mechanism to find out about it after the fact, except via a crash or other weird behaviors. The name of the game … | |
Re: So, why is the type of `info` a `void *` and not a `NODETYPE`? If `info` is supposed to contain the information associated to the node and that the node-type is `NODETYPE`, wouldn't it be logical that that would be the type of `info`? As so: template <typename NODETYPE> class … | |
Re: > I can use the `capture_man` object and all of its functions Very often, just calling a member function of an object doesn't actually require the object to be valid or even existing at all, it is only when you access the data members (either within the member function, or … | |
Re: First of all, for any type (string or other), the statement "if ( a = b )" does not check whether a is equal to b, it assigns the value of b to a, and returns the final value a (which is also the value of b). The single = … | |
Re: In the future, you should restrict one thread to one question. The discussion becomes difficult to have and to read when there are three separate issues in parallel. > They are the exact same syntax, it works for all my classes, why does it not work for literal types? I've … | |
Re: If you are using VS, then you can put this line at the very top of your source file: #pragma comment(lib, "wsock32.lib") Another option is to go into your project options menu and add the "wsock32.lib" to the list of external libraries to link to (amongst the list of all … | |
Re: > Do a depth-first traversal through the decisionspace, ordering by expected time of finishing the design having made that decision. Sounds more like an `A*` algorithm to me! ;) As for the OP's question, it is all a matter of picking your battles. You can't make everything perfect all the … | |
Re: Typo? template<typename T> CustomType<T>& CustomType<T>::Delete(CustomType<T> ValuesToDelete) // notice the <T> here. | |
Re: Whenever an object is `const`, it means that it cannot be modified. Like in the main() function, the object `cdi` is `const` and cannot be changed. Now, the problem is that if you call a member function (like `at()`) on that object, how can the compiler make sure that the … | |
Re: AFAIK, there is no legal equivalent in C++. And any attempts to reproduce the same behavior could be very tricky (I can think of one, and it's not pretty). What's wrong with access via the struct's name? It's not worth going through too much trouble just for a bit of … | |
Re: That is the code for [`wpa_supplicant`](http://en.wikipedia.org/wiki/Wpa_supplicant) which is the main GNU/Linux wireless network code to deal with secure wireless networks (I'm writing this right now through a wpa-supplicant connection). It apparently works under Windows too, but it is probably going to be harder to get it to compile. And if … | |
Re: All that AD said, plus these corrections: c) is **True**. A function prototype / declaration can appear anywhere (well, anywhere any other variable declaration can appear), this includes the global scope, namespace scope, class scope, function body, and even within any `{ }` scope within the function body. At least, … | |
Re: Most of your questions will find their answers in [my tutorial](http://www.daniweb.com/software-development/cpp/tutorials/373787/beginning-c0x-making-a-raii-class) on the subject. The tutorial involves C++0x / C++11 features (which is the new standard, not yet well-supported by compilers), you can just ignore those features. > The only problem I can possibly see with my bitmap class is … | |
Re: > I'm worried that the myVector.clear() takes time to actually clear all the memory. Also, does the myVector.reserve() survive the clear()? The clear() function will almost certainly not deallocate any memory, so, yes, the reserved capacity will remain. I say "almost certainly" because the C++ standard doesn't explicitly *require* that … | |
Re: Smart pointers are not meant to point to dynamic arrays, but to individual objects. Boost has a `shared_array` class to deal with arrays, but I wouldn't recommend it. In your case, you should be allocating your dynamic arrays using an STL container, in particular, `std::vector`. As so: std::vector<char> Buffer(1024); fread(&Buffer[0], … | |
Re: The compiler will treat this statement: std::set<unsigned long> empty (); as a function declaration. It will think that you are declaring a function that takes no parameters are returns a set of ulongs. To declare a default-constructed object, just use this: std::set<unsigned long> empty; And, btw, when you create a … | |
Re: We don't just do your homework for you. Post the code that you have made on your own so far, and ask specific questions about the problem(s) you have with it. You have to show some efforts. | |
Re: > Yeah, it's just that once the rpm is installed, the binary file has went from 50mb to 12mb - does the compression apply to the file even once it has been installed? You have been shy with details, but I can think of two possible causes. First, maybe your … | |
Re: > Why does this say shaddowing? Because your data members have the same name as your parameters. Whenever this happens, the compiler will always assume that when you refer to that variable name, you mean the variable with the most local scope, in this case, it would be the function … | |
Re: Analogy: You are a thread. You're looking for a room in a hotel, which is the resource. Because you are not alone, there can be several people coming in and out of the hotel at unpredictable times. So, the question is, how do you make sure not to over-book the … | |
Re: First of all, for `short` types, they are almost never preferrable, unless you are really concerned with memory consumption, and even then, it might not have any effect. In fact, the highest number that you need to store is rarely if ever the deciding factor (unless you are doing some … | |
Re: It is probably a simply typo. The string conversion produces a .NET string of type `System::String^`, not a C++ string of type `std::string`. If you use the lower-case name `string`, my guess is that it refers to `std::string`, which is not the same as `System::String^`. This should work: System::String^ makebreak1 … | |
Re: > I know .NET is a Microsoft framework. Yes. > I currently use Visual Studio 2008 for C++ programming in school. Am I using .NET? Maybe. C++ is a programming language that is fundamentally incompatible with .NET. However, Microsoft has a frankenstein language called C++/CLI which mixes C++ with .NET … | |
Re: Very often, if a function call is ambiguous to the compiler, it is also ambiguous to the programmer. In your code, there are two functions that do two very different things, the first returns the absolute value of a, and the second makes the given variable positive. Why are these … |
The End.