Search Results - CodeGuru Forums
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

Search:

Type: Posts; User: Philip Nicoletti

Page 1 of 80 1 2 3 4

Search: Search took 0.15 seconds.

  1. Re: sort vector of objects on member variable

    The bigger function that you supplied will not compile with the sort for result_holder.

    monarch_dodra supplied an example to sort int variables. You would need to change it for variables of type...
  2. Re: sort vector of objects on member variable

    You have:



    bool operator < (const result_holder& lhs, const result_holder& rhs)
    {
    return lhs.row_value > rhs.row_value;
    }
  3. Replies
    10
    Views
    315

    Re: How to do clone in vc++?

    It depends on the object. You need to provide more information .

    1) You might not to add any additional code to a class to copy an object.

    2) You might need to add copy semantics to your...
  4. Re: sort vector of objects on member variable

    If you make operator < a member function, it should only take one argument and be const:



    bool operator < (const result_holder& rhs) const
    {
    return row_value < rhs.row_value;
    }
  5. Replies
    12
    Views
    484

    Re: index position in array Issue

    You have:


    for (int q=0; q=size2;q++)


    This sets q = size2 every time thru the loop (and the loop never terminates)
  6. Re: remove duplicated from sorted vector

    It is not clear how the first two elements are equal. I guess if the second values of the pair are equal ?

    If so...



    #include <algorithm>

    struct EqualWeight
    {
  7. Replies
    6
    Views
    385

    Re: vectors with structure

    You can access using:



    for (vector<SP>::const_iterator it4=it->sl4.begin(); it4!=sl4.end(); ++it4)
    {
    cout << it4->sp1 << " : " << it4->sp2 << "\n";
    }
  8. Re: Debugger error - ftol3.asm not found

    from http://www.cplusplus.com/reference/string/string/find/



    size_t find (char c, size_t pos = 0) const noexcept;


    size_t is an unsigned integral type (the same as member type...
  9. Re: Debugger error - ftol3.asm not found

    1) you should #include <string>

    2) the type returned by string::find is string::size_type , not double

    3) in general, erasing an element while looping is tricky
  10. Replies
    2
    Views
    369

    Re: crypt a file [algorithm]

    1) You need to open the file as binary. Otherwise, if an EOF character is encountered, input will stop.

    2)


    std::string can handle embedded NULLS.
  11. Re: Run-Time Check Failure #3 - The variable is being used without being initialized

    That is interesting that a run time error occurs in the first example.
    It must occur during the copy when passing x by value. In other
    words, I would guess you would still get the error even if...
  12. Re: How to determine cross platform type during file save?

    Sorry, with further thought my original suggestion would not work.
  13. Re: Need Help with Binary Search Function

    while(high>low and high!=low)


    is legal. There are a number of alternate tokens like this ("bitor" , "xor" , "or" , etc).

    Personally, I would not use them as they are seldom seen in code.
  14. Replies
    11
    Views
    511

    Re: The issues with my piece of code

    1) I was not aware of the "= default" syntax ... good to know

    2) Unless I am missing something, it might be safer to supply them. Section 12.8.10 :



    edit: Upon re-reading the note, I think...
  15. Replies
    11
    Views
    511

    Re: The issues with my piece of code

    Here is an example of a 2D array class using a single vector<T> as a member.
    Element access is done using : arr((i,j) not arr[i][j]

    I added move semantics. You should add move semantics to your...
  16. Replies
    11
    Views
    511

    Re: The issues with my piece of code

    Yes, basically that is correct. Your code in the original post was for a 3D array, so it will call the constructor O(n^2) times.
  17. Replies
    11
    Views
    511

    Re: The issues with my piece of code

    OneDArray<OneDArray<OneDArray<int>>> arr;




    This is a simple, but inefficient way to create multi-dimensional
    arrays. As you noticed, the constructor (and hence new) is called
    many times...
  18. Re: A question regarding erasing an item from a vector

    And in your code you have:



    next = it+1;
    v.erase(it);


    The erase invalidates iterators and references at or after the point of the erase. So the "next" iterator has been invalidated.
  19. Re: A question regarding erasing an item from a vector

    Your loop should look like this:



    for(vector<int>::iterator it=v.begin();it!=v.end();/* nothing here*/)
    {
    if(*it == 14)
    {
    it = v.erase(it);
    }
  20. Re: A compiler error with the implementation of smart pointer

    I don't see that. operator= decrements the reference count and if equals 0, deletes the memory. Am I missing something ?
  21. Re: A compiler error with the implementation of smart pointer

    For shared_ptr and unique_ptr, it is up to the programmer to not dereference the owned pointer if it is the nullptr. I do not think the functions are allowed to throw, but the get() function can be...
  22. Replies
    2
    Views
    348

    Re: c++ weird error

    1) You should describe the error .. compile time ? run time ?

    2) you are accessing invalid indices in your array ...


    int list[100];

    for( int j=1; j<101; j++)
    {
    int i = rand()%61 + 40;
  23. Re: A question regarding double-checked locking

    Scott Myers and Andrei Alexandrescu wrote on this :

    http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf

    If you do not like clicking on links, do a search on:

    scott myers double...
  24. Re: A compiler error with the implementation of smart pointer

    Why would "a" become empty ? You have implemented a shared pointer.
    Both "a" and "b" share the pointer.
  25. Replies
    4
    Views
    348

    Re: Displays arrays

    Also note: arrays are stored in contiguous memory. Using that information, you can write a
    single function to compute the total of the array, no matter how many dimensions. The trick
    is to...
Results 1 to 25 of 2000
Page 1 of 80 1 2 3 4


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center