388 Posted Topics

Member Avatar for ztdep

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 …

Member Avatar for ztdep
0
1K
Member Avatar for FoxInBoots

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 …

Member Avatar for FoxInBoots
0
2K
Member Avatar for Sandhya212

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.

Member Avatar for Sandhya212
0
233
Member Avatar for Vivek0909
Member Avatar for johans22

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 …

Member Avatar for Derek Elensar
0
113
Member Avatar for phoneybone

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.

Member Avatar for phoneybone
1
111
Member Avatar for EEETQ

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 …

Member Avatar for NicAx64
0
230
Member Avatar for anaychowdhary

This looks like a version of the NP-complete [URL="http://en.wikipedia.org/wiki/Knapsack_problem"]knapsack problem[/URL] to me.

Member Avatar for anaychowdhary
-2
182
Member Avatar for khsheehan

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?

Member Avatar for arkoenig
0
157
Member Avatar for CrazyMisho

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.

Member Avatar for rubberman
0
141
Member Avatar for ankit.4aug
Member Avatar for noctiskram

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.

Member Avatar for arkoenig
0
881
Member Avatar for youLostTheGame

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 …

Member Avatar for arkoenig
0
140
Member Avatar for SourabhT

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

Member Avatar for arkoenig
0
721
Member Avatar for sha11e

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

Member Avatar for sergent
0
213
Member Avatar for fahadyousaf

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.

Member Avatar for \007
0
458
Member Avatar for yapkm01

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) { } }; …

Member Avatar for yapkm01
-1
321
Member Avatar for sdr001

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.

Member Avatar for sdr001
0
191
Member Avatar for Behi Jon

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 …

Member Avatar for arkoenig
0
146
Member Avatar for Nicco

How about inserting code before line 37 to verify that x and y are in range?

Member Avatar for Nicco
0
296
Member Avatar for PaulBird

Without seeing the program you tried to compile, there's not much anyone can do.

Member Avatar for rubberman
0
307
Member Avatar for fibbo

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 …

Member Avatar for fibbo
0
7K
Member Avatar for sergent

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

Member Avatar for arkoenig
0
547
Member Avatar for tometherton

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.

Member Avatar for tometherton
0
109
Member Avatar for SeePlusPlus2

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 …

Member Avatar for arkoenig
0
152
Member Avatar for schrope
Member Avatar for Tamlyn
Member Avatar for flyboy567
Member Avatar for mike_2000_17
0
158
Member Avatar for ntrncx

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

Member Avatar for template<>
0
206
Member Avatar for taumang

If you want to continue calculating other values, then you should continue calculating other values. What is preventing you from doing so?

Member Avatar for saadsaidi
0
132
Member Avatar for Colezy

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

Member Avatar for Colezy
0
116
Member Avatar for ChaseRLewis

Maybe you should use something other than an empty string in your #define statements. [CODE] #define NUMERIC_CONSTANTS_H 1 [/CODE]

Member Avatar for mike_2000_17
0
162
Member Avatar for usustarr

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.

Member Avatar for arkoenig
0
125
Member Avatar for ryannans
Member Avatar for arkoenig
0
229
Member Avatar for Jbvo

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

Member Avatar for Jbvo
0
314
Member Avatar for g_u_e_s_t

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 …

Member Avatar for rubberman
-1
482
Member Avatar for omidagha

Please read [URL="http://www.daniweb.com/software-development/cpp/threads/78223"]this[/URL].

Member Avatar for arkoenig
0
117
Member Avatar for HASHMI007

[URL="http://www.daniweb.com/software-development/cpp/threads/78223"]Here[/URL]'s the information you need.

Member Avatar for HASHMI007
-6
92
Member Avatar for mpassaglia

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

Member Avatar for mpassaglia
0
407
Member Avatar for mpike

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 …

Member Avatar for arkoenig
0
153
Member Avatar for bumsfeld

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?

Member Avatar for TrustyTony
0
2K
Member Avatar for Michael_Tanner

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 …

Member Avatar for Michael_Tanner
0
150
Member Avatar for failbot

Your begin, end, rbegin, and rend functions don't have any return statements in them, so they return garbage.

Member Avatar for arkoenig
0
85
Member Avatar for mitrious

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 …

Member Avatar for mitrious
0
161
Member Avatar for pandaEater

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.

Member Avatar for pandaEater
0
109
Member Avatar for chrispen

[URL="http://www.daniweb.com/software-development/cpp/threads/78223"]Here[/URL] is what you need to know.

Member Avatar for arkoenig
0
144
Member Avatar for Torien7

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 …

Member Avatar for Torien7
0
242
Member Avatar for margeaux54
Member Avatar for margeaux54
0
102
Member Avatar for charqus

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

Member Avatar for arkoenig
0
97
Member Avatar for blee93

Line 15 uses hobby as the first argument of strcpy without ever having initialized it.

Member Avatar for blee93
0
233

The End.