Type: Posts; User: Philip Nicoletti
Search took 0.15 seconds.
December 12th, 2014, 01:19 PM
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...
December 12th, 2014, 01:14 PM
bool operator < (const result_holder& lhs, const result_holder& rhs)
return lhs.row_value > rhs.row_value;
December 12th, 2014, 06:49 AM
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...
December 10th, 2014, 07:31 PM
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;
December 10th, 2014, 06:37 AM
for (int q=0; q=size2;q++)
This sets q = size2 every time thru the loop (and the loop never terminates)
December 1st, 2014, 08:04 PM
It is not clear how the first two elements are equal. I guess if the second values of the pair are equal ?
November 26th, 2014, 10:30 AM
You can access using:
for (vector<SP>::const_iterator it4=it->sl4.begin(); it4!=sl4.end(); ++it4)
cout << it4->sp1 << " : " << it4->sp2 << "\n";
November 25th, 2014, 06:21 PM
size_t find (char c, size_t pos = 0) const noexcept;
size_t is an unsigned integral type (the same as member type...
November 25th, 2014, 11:33 AM
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
November 17th, 2014, 08:15 AM
1) You need to open the file as binary. Otherwise, if an EOF character is encountered, input will stop.
std::string can handle embedded NULLS.
November 11th, 2014, 12:09 AM
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...
November 10th, 2014, 12:03 PM
Sorry, with further thought my original suggestion would not work.
November 9th, 2014, 05:00 PM
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.
October 31st, 2014, 05:57 PM
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...
October 31st, 2014, 03:39 PM
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...
October 31st, 2014, 02:30 PM
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.
October 31st, 2014, 07:04 AM
This is a simple, but inefficient way to create multi-dimensional
arrays. As you noticed, the constructor (and hence new) is called
October 28th, 2014, 07:59 PM
And in your code you have:
next = it+1;
The erase invalidates iterators and references at or after the point of the erase. So the "next" iterator has been invalidated.
October 28th, 2014, 07:43 PM
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);
October 26th, 2014, 06:05 PM
I don't see that. operator= decrements the reference count and if equals 0, deletes the memory. Am I missing something ?
October 26th, 2014, 06:03 PM
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...
October 24th, 2014, 12:51 PM
1) You should describe the error .. compile time ? run time ?
2) you are accessing invalid indices in your array ...
for( int j=1; j<101; j++)
int i = rand()%61 + 40;
October 24th, 2014, 08:50 AM
Scott Myers and Andrei Alexandrescu wrote on this :
If you do not like clicking on links, do a search on:
scott myers double...
October 23rd, 2014, 09:03 PM
Why would "a" become empty ? You have implemented a shared pointer.
Both "a" and "b" share the pointer.
October 23rd, 2014, 07:42 AM
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
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.