Search:

Type: Posts; User: laserlight

Page 1 of 20 1 2 3 4

Search: Search took 0.12 seconds; generated 7 minute(s) ago.

  1. Replies
    1
    Views
    44

    You might want to read these two technical...

    You might want to read these two technical dictionary entries for abstract data type and data structure. What you have in mind is the former, but when expressed in code we get the latter, which does...
  2. Replies
    12
    Views
    79

    It has to destroy the elements too, though in...

    It has to destroy the elements too, though in this case for int it isn't really relevant.


    And avoided the possibility of running into an assert on some implementation, methinks :p

    ...
  3. Replies
    8
    Views
    119

    You can use #define in a header; it is commonly...

    You can use #define in a header; it is commonly used to define named constants.

    Basically, if you have a header "other.h" that consists entirely of this:

    #define PI 3.1415
    And a "main.c" that...
  4. Replies
    8
    Views
    119

    That looks fine. Is this really the code that you...

    That looks fine. Is this really the code that you compiled? Is there anything that you left out or which isn't the same as what you compiled?
  5. That's because I had in mind comparing with...

    That's because I had in mind comparing with strlen: it would be easier to see that way since you can name the variable so the reader knows why it is compared to strlen. But if you're comparing with...
  6. You should be using strcspn instead of strspn,...

    You should be using strcspn instead of strspn, and you should be calling it separately in order to compare it with strlen, i.e., if the span that doesn't contain the invalid characters is equal to...
  7. Replies
    4
    Views
    109

    The "STL" stands for the "Standard Template...

    The "STL" stands for the "Standard Template Library", which is a collection of class templates and function templates providing generic algorithms, containers, and other connecting generic components...
  8. Replies
    2
    Views
    91

    I think fabi.mueller solved the problem...

    I think fabi.mueller solved the problem independently then removed the code.
  9. Replies
    6
    Views
    101

    For older versions of GCC, you might have to...

    For older versions of GCC, you might have to explicitly compile as C++11 with -std=c++11

    Well, at least I think this is a C++11 feature; if it was introduced in C++14 then you might be stuck, and...
  10. Replies
    6
    Views
    101

    You can do that: it sets the default member...

    You can do that: it sets the default member initialiser, although the initialisation itself is only done when the constructor is invoked, i.e., when the initialiser list would be run.
  11. Yes, it makes sense when you're dealing with...

    Yes, it makes sense when you're dealing with indices, though you have to be careful if you're looping from N-1 to 0 rather than the usual 0 to N-1.
  12. Replies
    1
    Views
    73

    It may be easier if you move your original...

    It may be easier if you move your original working code into a function, then call the function from main within the do while loop.
  13. Replies
    4
    Views
    109

    What's CTRL? As for "how object ORIENTED in...

    What's CTRL?

    As for "how object ORIENTED in C++ is accomplished": work through an introductory book or comprehensive tutorial on C++.
  14. Of course. You just need to decide on what you...

    Of course. You just need to decide on what you want the output to look like, and if you intend to read programmatically from file, you need to decide on an output format that can be read like that.
  15. Then there's no problem. You're using fwrite to...

    Then there's no problem. You're using fwrite to write a binary representation of the struct person object to file, so when you open the file as if it were a text file, you might find some unusual...
  16. Instead of: line.str(temp); Try: ...

    Instead of:

    line.str(temp);
    Try:

    istringstream line(temp);
    Note that this doesn't put the lines in the vector; it puts "words" extracted from the lines into the vector. If that's your aim...
  17. Replies
    10
    Views
    154

    ... and experience the pain of your code failing...

    ... and experience the pain of your code failing to compile because the header does not exist :p

    Or experience the pain of never having using namespace std; in your code, not even in local scopes,...
  18. I'm more interested in "straight insertion sort"....

    I'm more interested in "straight insertion sort". Canonical bubble sort is well known and quite clearly different from canonical insertion sort. The question here is whether this is an inefficient...
  19. Wait, I just realised that you wrote: "According...

    Wait, I just realised that you wrote: "According to Knuth (Vol 3) and Wikipedia the defining feature of insertion sort is that the terminating condition is when no swaps have occurred."

    That would...
  20. That's interesting: I've understood the defining...

    That's interesting: I've understood the defining feature of insertion sort as being "insert in relative position", whereas bubble sort's would be "always swap adjacent elements if out of order". That...
  21. It's legal because you know exactly what you're...

    It's legal because you know exactly what you're sorting: const void* objects. Basically, the idea is to sort pointers rather than the original int objects themselves. So, the sorted pointers will...
  22. It's bubble sort: the inner loop does repeated...

    It's bubble sort: the inner loop does repeated comparison of adjacent items and swaps them if they are out of order. The outer loop loops enough times to ensure that there are enough inner loop...
  23. That doesn't look correct to me: since arrToSort...

    That doesn't look correct to me: since arrToSort is a void*, arrToSort[i] is illegal as pointers to void cannot be dereferenced.

    By the way, it would be better not to typedef the pointer types...
  24. Poll: I agree, which is why I'm fine with overloading...

    I agree, which is why I'm fine with overloading operator<< for ostream. I'm also fine with what may be the most epic abuse of operator overloading ever: the Spirit parser framework, which tries to...
  25. I like the joke that subverts this koan to have...

    I like the joke that subverts this koan to have the Zen master slap (using one hand) the disciple who asked him to explain this koan.
Results 1 to 25 of 500
Page 1 of 20 1 2 3 4