388 Posted Topics
Re: Please read [URL="http://www.daniweb.com/forums/thread78223.html"]this[/URL]. | |
Re: [URL="http://www.daniweb.com/forums/thread573.html"]Here you go.[/URL] | |
Re: In the future, please post a complete program. However.... Even though this program is incomplete, I can see a serious problem: In C++, arrays start with an index of 0. So when you write a loop such as [CODE] for(int i=1; i<=month; i++) { monthAverage[i] = monthSum[i] / month; } … | |
Re: You have defined acknowledge_call to take eight arguments. You have called it with no arguments. Hence the error message. Next time, please use code tags. | |
Re: Your dealCard member function has a serious flaw: It returns a reference to a local variable, which will refer to nothing valid after the function has returned. You should probably just return a Card (assuming that Card is a class whose values you can copy). If you're going to use … | |
Re: Change "int i = 0" to "vector<string>::size_type i = 0" in line 44 and to "string::size_type i = 0" in lines 58, 71, and 84. Next time, please cite the text of the error message so we don't have to look it up. | |
Re: In line 11 you say that gpa_Sorter takes two arguments: a double and an int. In line 31 you call gpa_Sorter with an array of double. Thus the error message. | |
Re: You first. Otherwise it looks too much like you're asking someone else to do your homework for you. | |
Re: [QUOTE=LevyDee;1456560]I tried the second example there and I get the same runtime error. My runtime error is: Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)[/QUOTE] I'll bet you tried to execute [CODE]delete [] error;[/CODE] but because error isn't pointing to memory that was allocated with [ICODE]new[/ICODE], you mustn't delete it. | |
Re: If you're using consecutive integers for the map indices, why not just use a vector? Independently of that, it would seem to me that you could simply replace lines 8 through 11 of your code by a call to std::swap(theDeck[i], theDeck[r]) and delete line 4 entirely. | |
| |
Re: [URL="http://www.daniweb.com/forums/thread78223.html"]Here you go.[/URL] | |
| |
Re: What have you tried so far? Why doesn't it work? What sort of trouble are you having? | |
Re: Use begin() and end() the way you would for any other container. | |
Re: I'll reinforce what PhysicsExpert said: I see no reason to define a class here. That said, I'd like to point out some other problems with your code. Perhaps the most important problem is that what your program actually does is different from what you said you were asked to do. … | |
Re: Wouldn't you think that when someone posts a program in a C++ forum and asks for help, the program would actually be a C++ program? | |
Re: Yes, that's what it means. A reference to a pointer is useful for exactly the same reasons that a reference to any other type is useful. | |
Re: Show us what you've done so far. | |
Re: You can replace [code] for (unsigned long int k = 0; k < inTables[q].Items.at(j).Size; k++) inTables[q].Items.at(j).Data.push_back(tempItem[k]); [/code] with [code] inTables[q].Items.at(j).Data.insert(inTables[q].Items.at(j).Data.end(), tempItem, tempItem+inTables[q].Items.at(j).Size); [/code] with the same effect. However, it would not surprise me to learn that doing so does not change the speed of your program much. Unless you have … | |
Re: Break it into manageable chunks. Sort each chunk into a file. Merge the files into another file. | |
Re: You can't have an array of size 0, in the sense that every array type includes the number of elements as part of the type, and for the type to be well defined, the number of elements must be strictly positive. Part of the reason for this requirement is to … | |
Re: In line 1 of your code, you add an integer to what you claim is a vector. I don't know what you think that's supposed to do, but it's not well defined in standard C++. Four times in you code, you explicitly convert an enum to an int. That shouldn't … | |
Re: Sounds like you need to measure the time more accurately. I suggest wrapping another loop around the entire program to run it a thousand times or so, and figuring out from that how long it takes to run once. | |
Re: You've initialized myList to myList, creating a circular reference that then you cannot undo. I think you will make your life easier if you use a pointer instead of a reference. | |
Re: What is the difference between decimal random numbers and other kinds? Putting it differently, exactly what are you trying to do? | |
Re: [QUOTE=Narue;1445456][ICODE]if(test_command == true)[/ICODE] should be [ICODE]if(test_command() == true)[/ICODE].[/QUOTE] Yes. But there's another subtle point here that is worth mentioning. It is generally a bad idea to write expressions of the form [icode]function() == true[/icode]. It is harmless to do so if the function returns a bool value, as test_command does … | |
Re: [QUOTE=vijayan121;1438221]Since x, y are integers limited to the inteval [ -100, +100 ] there are just 200*200 == 40000 possible tuples (x,y). Just use brute force.[/QUOTE] 201 * 201 = 40401 possible tuples. | |
Re: [QUOTE=lulzy;1436726]But, in my case, the classes A, B and C don't contain values by which they could get sorted and that's the trick. [/QUOTE] Of course they do! That's the point of the value function Narue suggested. You override that function in each of your derived classes to return a … | |
Re: Maybe your compiler doesn't completely support C++0x initializations yet. What happens if you replace the curly braces with parentheses in the last line of code in your example, and change "auto" to "AoE2Wide::Item*" ? | |
Re: The variable "last" you use in line 7 isn't defined, nor is it given a value anywhere. If your list has only a single element, then presumably after you remove it, you need to set head to 0. Nowhere in the code is it possible for that to happen. | |
Re: You've been studying this subject for two years. Surely you must be able to do [I]something[/I]. So how about showing us how much of your program you've written successfully. Then you might get a hint as to what to do next. | |
Re: Yes. More seriously, if you're running this program on a 32-bit machine, you're probably asking for much more memory than the system is capable of providing; and it would not be surprising to learn that an overflow is taking place as part of computing how much memory you need. | |
Re: This code has lots of small errors that I'm going to leave it to you to find. I'll just point out the big error. Lines 47-66 read all the contents of in2. When you're done, you've reached the end of in2. Now line 67 tests whether you've reached the end … | |
Re: A somewhat easier way to write [CODE] copy(d1.begin(), d1.end(), d0); copy(d2.begin(),d2.end(), &d0[d1.size()]); copy(d3.begin(),d3.end(), &d0[d1.size()+d2.size()]); [/CODE] is as follows: [CODE] double* next = copy(d1.begin(), d1.end(), d0); next = copy(d2.begin(), d2.end(), next); next = copy(d3.begin(), d3.end(), next); [/CODE] After this code, next points to the first available location in d0. | |
Re: The recursive call to CheckSmaller (with the comment) will never be executed because either path of the if statement before it will return first. So I don't even need to read the rest of the code to see that it's wrong. | |
Re: What do you think happens when you execute the following? [CODE] { link_list x; x.insert(42); link_list y = x; } [/CODE] | |
Re: There is no way to determine where in a file each line begins without reading the entire file (unless you're creating the file, in which case you can remember the line locations as you write them--but that's the same kind of operation as reading it). So I don't see any … | |
Re: It's hard to believe that this is your actual code, because you don't declare a return type for any of your print functions. I see no reason why calling print on a pointer to a C object should call anything but C::print, so I can only conclude that your problem … | |
Re: Two points: 1) Why do you think your code was executed correctly? Is it not possible that it just happened to appear to be correct by coincidence? How would you go about proving that it was executed correctly even without a copy constructor. 2) If you have a copy constructor, … | |
Re: You can't do it directly, and it's hard to understand why you would want to so--because if you could, the [I]behavior[/I] of your program would depend on the names you choose for its components. | |
Re: Well, yeah. Line 7 defines situation as a reference to an object of type BattleSituation that you have promised not to change (because you defined it as a reference to const). Line 9 calls the getHPData member of situation. That member is permitted to change the value of its object … | |
Re: Why don't you start by describing your ideas? Then other people will be more likely to contribute theirs. | |
Re: Shouldn't line 75 be assigning to data[size], not data[size-1]? Also, what does Q_memcpy do? That's anot a standard function, and you don't include its definition. | |
Re: Step 1. Understand the problem thoroughly. Step 2. Realize that I was really serious about step 1, and go back and understand the problem even more thoroughly. Step 3. Write the clearest, most straightforward program you can that solves the problem correctly. Step 4. Measure your program's performance. If you're … | |
Re: There are no 2D vector types in standard C++. There are only vectors of vectors (or vectors of maps, or whatever). |
The End.