388 Posted Topics

Member Avatar for joshalb

[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]

Member Avatar for arkoenig
0
161
Member Avatar for Fzn10

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: …

Member Avatar for sruthivin
0
101
Member Avatar for onako

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 …

Member Avatar for mike_2000_17
0
4K
Member Avatar for priyanka.js28

[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 …

Member Avatar for arkoenig
0
264
Member Avatar for vavazoom

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 …

Member Avatar for mike_2000_17
0
216
Member Avatar for vidyasmani

[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 …

Member Avatar for arkoenig
0
106
Member Avatar for Kanoisa

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.

Member Avatar for arkoenig
1
183
Member Avatar for Frederick2

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.

Member Avatar for Frederick2
0
643
Member Avatar for newbiecoder

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 …

Member Avatar for arkoenig
0
439
Member Avatar for Frederick2

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!

Member Avatar for Fbody
0
357
Member Avatar for hockeygurl35
Member Avatar for ischuldt
Member Avatar for arkoenig
0
124
Member Avatar for stevebush

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.

Member Avatar for AuburnMathTutor
0
111
Member Avatar for kshitij tyagi
Member Avatar for arkoenig

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 …

Member Avatar for 0x69
0
131
Member Avatar for Excizted

Can you show us what your copy constructors and assignment operators are for Vector3 and Quaternion?

Member Avatar for Excizted
0
196
Member Avatar for barathdon

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 …

Member Avatar for arkoenig
0
89
Member Avatar for Andreas5

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. …

Member Avatar for Andreas5
0
190
Member Avatar for ChPravin

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 …

Member Avatar for TrustyTony
0
1K
Member Avatar for maria99

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 …

Member Avatar for maria99
0
383
Member Avatar for jeevsmyd

[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.

Member Avatar for TrustyTony
0
1K
Member Avatar for Sandeep929

You will find your answers [URL="http://www.daniweb.com/forums/thread573.html"]here.[/URL]

Member Avatar for arkoenig
-3
71
Member Avatar for Chaos3737

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() …

Member Avatar for arkoenig
0
152
Member Avatar for dansnyderECE

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, …

Member Avatar for Aranarth
0
98
Member Avatar for bbman

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.

Member Avatar for jonsca
0
100
Member Avatar for avarionist

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 …

Member Avatar for avarionist
0
243
Member Avatar for noobuser

Perhaps a more interesting question is why you have a 200000-element array that needs initializing in the first place.

Member Avatar for Ancient Dragon
0
207
Member Avatar for DelilahDemented

[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 …

Member Avatar for arkoenig
0
222
Member Avatar for highflyer8

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.

Member Avatar for arkoenig
0
1K
Member Avatar for Pinchanzee

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].

Member Avatar for Pinchanzee
0
159
Member Avatar for KAY111

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.

Member Avatar for arkoenig
0
116
Member Avatar for NathanOliver

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.

Member Avatar for NathanOliver
3
330
Member Avatar for romyboy2k9

Your struct `node` has a data member named `info` that you define but never use. What purpose does it serve?

Member Avatar for thelamb
0
126
Member Avatar for glenc70

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)

Member Avatar for Nick Evan
0
100
Member Avatar for bubacke

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 …

Member Avatar for bubacke
0
484
Member Avatar for danizobin

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; …

Member Avatar for danizobin
0
194
Member Avatar for RayvenHawk

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?

Member Avatar for mrnutty
0
165
Member Avatar for kenji

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, …

Member Avatar for arkoenig
0
154

The End.