Forum: C++ Aug 30th, 2008 |
| Replies: 1 Views: 1,670 That's how a stack works, it's a "last-in, first-out" structure. The item at the top will always be the last item that was pushed:
#include <iostream>
#include <stack>
int main()
{
using... |
Forum: C++ Aug 22nd, 2008 |
| Replies: 3 Views: 1,763 The only thing Edward can think of is using a union like that isn't required to work even if the conversion is safe but a reinterpret_cast<> is. The rules say that assigning to one member of a union... |
Forum: C++ Aug 22nd, 2008 |
| Replies: 5 Views: 624 // Star is in the wrong place
void Field::*data(){
return NULL;
}
// Star is in the wrong place
// void* is the wrong return type
void Field::*clone() const{
return NULL;
} |
Forum: C++ Aug 18th, 2008 |
| Replies: 4 Views: 684 One of Ed's favorite books is Inside the C++ Object Model (http://www.amazon.com/Inside-Object-Model-Stanley-Lippman/dp/0201834545). You're asking for a lot of hardcore low level info, and I doubt... |
Forum: C Aug 16th, 2008 |
| Replies: 2 Views: 390 break from the inner loop and then continue from the outer loop. If there's more to the body, you may need a flag or something similar:
while (condition) {
int nextIteration = 0;
while... |
Forum: Geeks' Lounge Aug 13th, 2008 |
| Replies: 7 Views: 730 Edward is a strong believer in professional behavior. If the dispute is trivial, just let it go. If it's not trivial, avoid an immediate confrontation and file a complaint through the proper channels. |
Forum: C++ Aug 11th, 2008 |
| Replies: 1 Views: 371 The ideal way to do this is to encapsulate the data into an object that defines a comparison operator. Then you can sort the objects instead of trying to sort parallel arrays:
#include <algorithm>... |
Forum: C++ Aug 11th, 2008 |
| Replies: 9 Views: 3,347 >still use strtol()
Better to use stringstream:
#include <ios>
#include <iostream>
#include <sstream>
int main()
{
using namespace std; |
Forum: C++ Aug 10th, 2008 |
| Replies: 4 Views: 746 #import isn't available in C or C++, but if you want the same effect of it, some compilers implement a special #pragma for header files called once:
#pragma once
// Header contents
That's... |
Forum: C++ Jun 16th, 2008 |
| Replies: 4 Views: 421 Your use of pointers seems a little backwards, but the tree in your sample program is valid. Ed used a formatted display algorithm to see how it's structured. Here's something that is a bit more... |
Forum: C++ Jun 16th, 2008 |
| Replies: 12 Views: 2,669 > That means, if one omits the for-init statement the semicolon also disappears.
That's not quite right, but Edward can easily see why you'd think that. Like most stuff in the standard, you have to... |
Forum: C++ Jun 13th, 2008 |
| Replies: 2 Views: 516 Neither Matrix nor VNT need an explicit destructor, but the real problem is in the destructor for those two classes you try to delete objects that weren't returned by new:
> delete mat;
mat isn't... |
Forum: C++ Jun 13th, 2008 |
| Replies: 12 Views: 1,642 > Meaning, if I opened up a table of contents, what would I look under to learn more about this subject.
Operator overloading, and probably stream I/O too. The exactly thing is overloading the... |
Forum: C++ Jun 13th, 2008 |
| Replies: 12 Views: 1,642 > The char datatype is not guaranteed to be stored in a single byte, either.
char is guaranteed to equate to a byte, but a byte isn't guaranteed to be 8 bits. I think that's what you meant. |
Forum: Computer Science Jun 10th, 2008 |
| Replies: 3 Views: 1,545 > How should I calculate the similarity between any two words?
The Levenshtein distance (http://www.merriampark.com/ld.htm) algorithm is a good place to start. |
Forum: C++ Jun 9th, 2008 |
| Replies: 6 Views: 886 > But the following code is not working.c
Did you include the code for compose2? It's not a standard STL function, but Edward would guess that you mean to use the one defined in Nicolai Josuttis'... |
Forum: C++ Jun 6th, 2008 |
| Replies: 9 Views: 2,425 > I have never in over 20 years seen anyone code a function prototype like that.
Edward has, but everyone has different experiences so there's no point arguing about what we've seen. :)
> Arrays... |
Forum: C++ Jun 5th, 2008 |
| Replies: 4 Views: 668 The only real problem Edward sees is that you don't resize the dynamic array after the first call to AddFirst or AddLast. If you don't allocate the memory, you can't reliably write to it. Here is a... |
Forum: C++ Jun 4th, 2008 |
| Replies: 4 Views: 729 > Why use getch() when there's a standard function: getchar()?
Because getchar() doesn't do what Edward needed.
getchar() is completely segregated from the console buffer such that the buffer... |
Forum: C++ May 29th, 2008 |
| Replies: 4 Views: 421 Initializing numb is easy. Just start at 1 and double the last value until you get to the size of the array:
int k = 1;
for (int i = 0; i < 10; ++i) {
numb[i] = k;
k *= 2;
}
... |
Forum: C++ May 27th, 2008 |
| Replies: 20 Views: 36,240 That's why Edward puts as much code as possible in namespaces. Compilers are bad about including all kinds of unexpected stuff in the standard headers, so even if you don't include unistd.h yourself,... |
Forum: C++ May 15th, 2008 |
| Replies: 5 Views: 480 > there is no way to have separate classes from the class main()....
There isn't a class that contains the main function like in Java. main() is a global function and you can have it in a separate... |
Forum: C May 15th, 2008 |
| Replies: 3 Views: 3,281 fgets reads a single line of characters, but fread reads a block of unidentified objects. fgets uses '\n' as a delimiter, but fread doesn't inspect any of the objects so it relies on a limit of the... |
Forum: C++ May 8th, 2008 |
| Replies: 34 Views: 2,350 > What is so difficult to understand about this:
Is that a trick question? Of course it's difficult to understand if you haven't learned how it works yet. :-O Edward learned long ago that just... |
Forum: C May 7th, 2008 |
| Replies: 4 Views: 794 > I found the problem thanks to your example!
Woohoo! :) Just remember that sprintf and sscanf are exactly the same as fprintf and fscanf except they use strings instead of files. That's how Ed... |
Forum: C++ May 7th, 2008 |
| Replies: 6 Views: 2,578 Edward is guessing about how your tree interface is, but something like this makes sense if you're making a copy of the current tree and need a full tree in return:
//
// Non-recursive user... |
Forum: C++ May 6th, 2008 |
| Replies: 2 Views: 430 You're printing the address of the pointer, not the address of the memory pointed to. Remove the address-of operator from your cout statement and you'll get the address of the memory that new gives... |
Forum: C++ May 6th, 2008 |
| Replies: 2 Views: 475 > Horse h1(Distance(p));
This is an evil bug. C++ isn't seeing that line as an object definition, it's seeing the line as a function declaration. h1 is a function that returns a Horse object and... |
Forum: C++ May 5th, 2008 |
| Replies: 6 Views: 2,578 > This should do what i want correct?
That's it. :) If you declare a pointer to BSNode<T>, that's all you have, a pointer. You can't reliably use that pointer until you set it to point to null or an... |
Forum: C++ May 3rd, 2008 |
| Replies: 6 Views: 1,565 gydytojas is a struct, but you use it like an object. The problem is the same as if you tried to say int.value = 5;, and the fix is to define a variable of gydytojas to work with. :) |
Forum: C++ May 2nd, 2008 |
| Replies: 5 Views: 558 You should abstract your data into objects so that it's easier to make changes and the design is clearer. Right now you have three vectors of data that should be encapsulated in a student class:
... |