388 Posted Topics
Re: I think that before you suggest solutions to a problem, it is important to understand exactly what problem you are trying to solve. When you say that you "want to make sure whether two points are the same," exactly what do you mean? In other words, will you ever want … | |
Re: Your problem is that in line 12, you try to calculate the values of num1-1 and num2-1 before you have given values to num1 and num2. If this information is not enough to allow you to fix your problem, then you don't really understand how variables work, and you need … | |
Re: If you want help with your code, you have to post the code that is having problems. You can't expect people to figure out what's wrong by looking at different code. | |
| |
Re: You need to specify the problem more precisely, because 1678.6 is probably not exactly representable as a double. So the question arises as to how close a representation you are willing to accept. The obvious solution would be to multiply the number by 10, round to the nearest integer, and … | |
Re: I think it would be more useful to talk (probably in another thread) about what characteristics make a C++ book useful and which books have those characteristics. If people just post books they like, reading that post doesn't tell you much because you know nothing about who posted it. | |
Re: Line 298 of your code inserts an entry into your map that contains the address of a local variable. When function execution finishes at line 300, that local variable goes away, leaving a dangling pointer in the map. Later, when you try to access the object to which the pointer … | |
Re: This looks like a version of the NP-complete [URL="http://en.wikipedia.org/wiki/Knapsack_problem"]knapsack problem[/URL] to me. | |
Re: What's the error? Compile time or run time? If run time, have you tried putting in code to determine just which statement is causing the trouble? | |
Re: Two things as starting points: 1) In your second code fragment, you have two members named next. You can't do that. 2) This is really a C program, not a C++ program, so you would be better off asking your question in the C forum. | |
Re: The statements on lines 29 and 31, among others, are nonsense. If you do not understand why, please study your textbook until you do. This is too fundamental a misunderstanding to be worth spending the time to explain. | |
Re: You said that your teacher gave you code that contains the line: [CODE] COORD thing = (x, y);[/CODE] Either you are mistaken or you should get another teacher. Because this line of code has the same effect as writing [CODE] COORD thing = y;[/CODE] but the form in which it … | |
Re: [QUOTE=SourabhT;1546176]i know how to do safe downcasting ,but my question is when i typecasted the base object to derived then pointer should call the fun() of derived (from virtual function call mechanism ) correct me if i am wrong !! [/QUOTE] OK, you're wrong. If D is derived from B, … | |
Re: [QUOTE=Narue;1544244]I have yet to see anyone nail down a concrete, consistent, and agreed upon definition of object orientation that excludes C++.[/QUOTE] Well, Bjarne once defined object orientation as "slow graphics" -- but as he was being only partly serious, that definition only partly counts. | |
Re: O(f(x)+g(x))=O(g(x)) whenever f(x) grows more slowly than g(x) as x increases without bound. Therefore, O(x+x^3)=O(x^3), and O(n+(n^2)log n)=O((n^2)log n). If you don't understand this, it means you need to learn about big-O notation in more detail. | |
Re: Here's the answer to the original question. If you have a class that defines one or more constructors explicitly, but does not define a default constructor, then every object of that class must be explicitly initialized. For example: [code] struct A { int n; A(int i): n(i) { } }; … | |
Re: I see nothing wrong with the code you've posted. Please post a small, complete file together with the error message you get when you try to compile it. | |
Re: Because you can write [CODE]vector<int, some_other_allocator<int> > v;[/CODE] and if [icode]some_other_allocator[/icode] is appropriately defined, you can impose a vector data structure on memory that is allocated in a way that [icode]some_other_allocator[/icode] defines. Many people will go through their entire careers without ever needing to do this, but it's there for … | |
Re: How about inserting code before line 37 to verify that x and y are in range? | |
Re: Without seeing the program you tried to compile, there's not much anyone can do. | |
Re: I suspect the solution is [CODE]std::vector<passenger*>& passenger_queue::passengers_at_floor(int floor_) [COLOR="Red"]const[/COLOR][/CODE] The point is that at present, passengers_at_floor is permitted to modify its object, but you're passing it a const object, namely the key from a map. So you need to add const to the definition of passengers_at_floor, as a promise that … | |
Re: [QUOTE=WaltP;1523875]I have heard that [B]Knuth[/B] actually designed an algorithm that [I]required[/I] a GOTO.[/QUOTE] Unless you can provide a citation, I'm skeptical. | |
Re: The problem you are trying to solve is a variation of the [url=http://en.wikipedia.org/wiki/Knapsack_problem]Knapsack Problem[/url]. There is no exact, general, efficient solution to this problem. | |
Re: The reason that you are permitted to use the "this" pointer with a static data member, even though the pointer is ignored, is so that you can write a statement such as [CODE]p->v = 42;[/CODE] without having to know whether v is static. Otherwise, you would have to figure out … | |
Re: Why not use the sort algorithm from the C++ standard library? | |
Re: If you are trying to solve the problem of putting eight queens on a chessboard so that none of them attacks any of the others, your program is dramatically larger than it needs to be. You can find a shorter solution [URL="http://en.wikibooks.org/wiki/Algorithm_Implementation/Miscellaneous/N-Queens"]here[/URL]. | |
Re: If you want to continue calculating other values, then you should continue calculating other values. What is preventing you from doing so? | |
Re: [QUOTE=Colezy;1512664]I have simply redefined the offending constructor in my cpp file, this is working fine but is it safe? [/QUOTE] No. [QUOTE=Colezy;1512664] What should I do to make it safe? Bearing in mind that I cannot edit the offending code directly as it has already been distributed. [/QUOTE] Don't try … | |
Re: Maybe you should use something other than an empty string in your #define statements. [CODE] #define NUMERIC_CONSTANTS_H 1 [/CODE] | |
Re: When you call check2(drives), the formal parameter is an Array. That means that drives is copied and what check2 sees is a copy of it. Is that what you intend? If not, the parameter should probably be Array&. It's hard to say more without seeing all the code. | |
Re: @Akill10: line 8 should have semicolons, not commas. Tut, tut. | |
![]() | Re: Suppose n is the number you're looking for. Then: [CODE]const int chunksize = 370000, numletters = 26; assert(n < numletters * numletters * chunksize); int chunkno = n / chunksize; int digit1 = chunkno / numletters; int digit2 = chunkno % numletters; const char* alphabet = "abcdefghijklmnopqrstuvwxyz"; string filename = … ![]() |
Re: Here's a recursive solution that's that's tricky enough that if you turn it in, your teacher will probably realize that you did not write it yourself: [CODE] void cubes1(int i, int n) { if (i <= n) { cout << i*i*i << ' '; cubes1(i+1, n); } } void cubes(int … | |
Re: Please read [URL="http://www.daniweb.com/software-development/cpp/threads/78223"]this[/URL]. | |
![]() | Re: [URL="http://www.daniweb.com/software-development/cpp/threads/78223"]Here[/URL]'s the information you need. ![]() |
Re: In your search function, counter should be a reference, not a pointer. So you should delete the * on line 17, and in line 98, you should change "int * counter" to "int & counter". | |
Re: It's not easy to replace a line of text in a file, because if the replacement line is a different size than the original, you have to change the positions of the remaining characters in the file. Unless you want to get into databases, the easiest most reliable way to … | |
Re: If you're going to generate a list of primes, rather than testing whether a single integer is prime, then why not use the list itself for the divisors? | |
Re: To give you an idea of how many worms are in this particular can, I'd like to isolate two lines from the OP's code: [CODE] delete this; const_cast<myclass *>(this) = 0; [/CODE] The program is already broken at this point, because once you have executed "delete this;" any subsequent use … | |
Re: Your begin, end, rbegin, and rend functions don't have any return statements in them, so they return garbage. | |
Re: Saying "it just won't work" doesn't really give readers much to go on. However, I will say that your iterator has several problems: 1) It defines == and != as members rather than friends. Worse, it defined them only recursively. In other words, you're defining it1==it2 by saying that it's … | |
Re: You haven't shown the definitions of your classes. I presume your MyChild classes are derived from MyBase. In that case, I see nothing wrong with your code except that your MyBase class [I][B]must[/B][/I] have a virtual destructor for it to work correctly. | |
Re: [URL="http://www.daniweb.com/software-development/cpp/threads/78223"]Here[/URL] is what you need to know. | |
Re: Your download function doesn't contain a return statement, which means that it doesn't return a value. So when you execute line 34, the variable "lines" is set to None. In line 35, when you try to select elements of Lines, the Python system tells you that you can't select elements … | |
Re: Option #3 is by far the best, in my humble but correct opinion. | |
Re: When the call to scanf in line 18 returns, it leaves unread in the input stream the first character that cannot possibly be part of an integer. In this case, that is the newline that ends the input. As a result, the first call to gets reads an empty line, … | |
Re: Line 15 uses hobby as the first argument of strcpy without ever having initialized it. |
The End.