388 Posted Topics
Re: [QUOTE=mike_2000_17;1293249]@StuXYZ.. just a little important correction, the OP should add: [CODE]virtual ~baseClass() {}; //notice the ~ for destructor[/CODE] check also [URL="http://www.daniweb.com/forums/thread300907.html"]this thread[/URL] on a very similar topic.[/QUOTE] One more little correction: [CODE]virtual ~baseClass() {} // no semicolon[/CODE] | |
Re: String literals have type "pointer to const char" and should not (and, in many circumstances) cannot be passed to function arguments of type "pointer to char" Bad: [CODE] extern void foo(char *); void bar() { foo("Hello"); /* attempted conversion of const char * to char * */ } [/CODE] Good: … | |
Re: Suppose you have an object of a type std::vector<VectorRam>. That object contains elements, each one of which is an object of type VectorRam. If you want to free the memory that those VectorRam objects occupy, there are two ways to do so: 1) Free the vector itself. That is, if … | |
Re: [QUOTE=mike_2000_17;1292653]You need to make the destructor in the base class as virtual (otherwise the base class destructor will be called directly). [/QUOTE] A small, pedantic, correction: You need to make the destructor in the base class virtual, otherwise the effect is undefined (Most implementations call the base-class destructor without first … | |
Re: This is more code than I want to bother reading without a clue as to what I'm looking for. However, the following oddity did jump out at me: The for statement on line 10 has as its subject the while statement on lines 11 through 19. Is that what you … | |
Re: [QUOTE=vidyasmani;1289806]I tried the following code in my Turbo C++ .. [CODE]int j=5; cout<<++j + ++j + j++;[/CODE] and got the result 20, as expected. [/QUOTE] Your first mistake is having any expectations at all about this statement. It tries to modify the value of j twice (or more) in the … | |
Re: You are exactly right about the point of the question. The question is there in order to encourage readers to stop thinking about data formats in terms of absolute sizes, and to try to write programs with output that conforms to the data being displayed. | |
Re: If you're serious about writing C++ programs, rather than writing C programs and using a C++ compiler to compile them, [icode]std::fill[/icode] is a better choice than [icode]memset[/icode] because it's type-safe and works even for class types. | |
Re: The problem is solvable in principle, but it isn't easy. Here's why. Suppose you're trying to obtain a random number between 0.0 and 1.0, and you want the result to be uniformly distributed. That does not mean you want every possible floating-point number to appear equally likely, because the little … | |
Re: You don't like how C defines integer division, and from that you conclude that it has no advantages over assembly language? Surely you're joking! | |
Re: What you should [I]really[/I] do is use [icode]std::string[/icode] instead of char arrays. | |
Re: Please post a short, complete example that illustrates the problem. | |
Re: How much memory are you allowed to use? Are you allowed to reorder the smaller list? Without answers to these questions, I don't see how to answer the original question. | |
Re: What would you do with the information if you had it? | |
You are given a one-dimensional array of signed integers. Find the (contiguous) subarray with the largest sum. If none of the array elements are negative, the solution is obviously that the subarray is equal to the entire array, so the problem is interesting only if the integers are signed. There … | |
Re: Can you show us what your copy constructors and assignment operators are for Vector3 and Quaternion? | |
Re: The answer is that the program does not work, because the line that assigns a value to [icode]c[/icode] has undefined behavior. The behavior is undefined because it attempts both to fetch and store the value of a single object between sequence points. Because the program does not work, there is … | |
Re: Your code has an interesting strategy, but it has a few problems. First, the C++ standard defines [icode]erase[/icode] to work by copying elements from the part of the vector after the erasure on top of the elements being erased, then destroying the elements at the end of the original vector. … | |
Re: If every element points to a subsequent element, where does the last element point? By definition, no element can be subsequent to the last one. So the problem as stated makes no sense. Once we have figured out exactly what the problem is, it may be possible to come up … | |
Re: I do not believe that you are showing us the actual code. My reason for this disbelief is that you define a variable named [icode]maclu[/icode] but then you [I]use[/I] a variable named [ICODE]maclu1[/ICODE]. In order for this code to work, therefore, you must have defined [ICODE]maclu1[/ICODE] somewhere, but you have … | |
Re: [QUOTE=jeevsmyd;1267931]one more doubt , 1s complement of zero can either be 1,1111 or 0,1111, right? when you take the complement of a number, you gotta take the complement of the sign bit also, right?[/QUOTE] No. 1s complement of zero is either 1,1111 or 0,0000. | |
Re: You will find your answers [URL="http://www.daniweb.com/forums/thread573.html"]here.[/URL] | |
Re: Using rand() % n for a random number between 0 and n-1 gives results that are generally not random, even if rand() itself is perfect. To see why, assume that rand() returns a 32-bit signed value, i.e. a value between 0 and 2147483647, inclusive, and that you are computing rand() … | |
Re: If the #1, #2, etc. strings are unique and recognizable without knowing whether they're needed, then just make a single preliminary pass through the file, finding all such strings, and putting them into a map that leads to their locations. Then, each time you want to locate such a string, … | |
Re: Lines 10 and 11 in ItemGroup make no sense. Line 10 sets _items[i] to a value, and line 11 immediately overwrites that value with a different value. Once you figure out what the code is supposed to be doing, I suspect that the solution to the problem will be straightforward. | |
Re: When you apply [icode]sizeof[/icode] to an object of type [icode]string[/icode], you get the amount of memory that needs to be allocated for an object of that type, exclusive of dynamic memory. This number has nothing to do with the number of characters in the [icode]string[/icode], so the results you get … | |
Re: Perhaps a more interesting question is why you have a 200000-element array that needs initializing in the first place. | |
Re: [QUOTE=nbaztec;1259752]The gentlemen above me have done a great job & answered well. I'd just like to add that chars inside switches are in fact converted to their ASCII equivalent ints. :)[/QUOTE] Not quite. A char is just an integer with (usually) severe constraints on its value. Operations that involve chars … | |
Re: exp(-10^5) is so close to zero that you're not going to be able to represent it as a floating-point number--zero will be the closest approximation. | |
Re: I have to say that I don't like either alternative, becuase there is a much simpler, cleaner one. There is a built-in function named [icode]getattr[/icode] with the property that [icode]getattr(x, 'a')[/icode] yields the value of [ICODE]x.a[/ICODE]. Similarly, [icode]setattr(x, 'a', y)[/icode] has the same effect as [icode]x.a = y[/icode]. | |
Re: The definition of the type Xnode is missing. Once you have found the .h file that defines it, you should put include statements for that file in appropriate places. | |
Re: I hate to rain on people's parades, but the original post says that it requires a bidirectional iterator. In fact, the code does <= comparisons on iterators--which means that it really requires random-access iterators. | |
Re: Your struct `node` has a data member named `info` that you define but never use. What purpose does it serve? | |
Re: Is there a reason that you used "new" instead of using a vector? (By the way, your example cannot work as you posted it, because [CODE]class[/CODE] is a reserved word that you cannot use as a name for your own type) | |
Re: If, for some reason, the while loop does not execute at all, then vtoks will not have any elements and the statement [CODE]cout << vtoks[0];[/CODE] will yield undefined behavior (such as the run-time error message you cited). So I would start by verifying that the file was actually opened correctly … | |
Re: You haven't actually asked a question; you've made a claim. As it happens, that claim is false, and it is false for a good reason. Consider: [CODE] class Foo { /* something */ }; class Bar: public Foo { public: void f(double); }; // ... void x() { Bar b; … | |
Re: I think it is very unlikely that the best solution to this problem will involve a two-dimensional array. An array of structures, perhaps, or (better) a vector of structures; but not a two-dimensional array. How about posting a code fragment that illustrates your problem? | |
Re: I think you are misunderstanding the exercise. The quartiles of a set of data have nothing to do with groups of four numbers. Rather, the notion of a quartile is a generalization of the notion of a median. In other words: To find the median of a set of numbers, … |
The End.