Click here to Skip to main content
15,892,537 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionC Language Tutorial Pin
tgsb11-Dec-13 22:00
tgsb11-Dec-13 22:00 
AnswerRe: C Language Tutorial Pin
Richard MacCutchan11-Dec-13 22:07
mveRichard MacCutchan11-Dec-13 22:07 
QuestionHow to get the android nowtime screen-picture from PC by adb ?? Pin
chehongyang11-Dec-13 19:41
chehongyang11-Dec-13 19:41 
AnswerRe: How to get the android nowtime screen-picture from PC by adb ?? Pin
Albert Holguin12-Dec-13 4:16
professionalAlbert Holguin12-Dec-13 4:16 
Questionto show an color filled object on the top of everything Pin
transoft11-Dec-13 8:34
transoft11-Dec-13 8:34 
AnswerRe: to show an color filled object on the top of everything Pin
Chris Losinger11-Dec-13 10:39
professionalChris Losinger11-Dec-13 10:39 
AnswerRe: to show an color filled object on the top of everything Pin
Albert Holguin12-Dec-13 4:19
professionalAlbert Holguin12-Dec-13 4:19 
Questionstd::swap Corruption [Answered] Pin
Skippums11-Dec-13 7:26
Skippums11-Dec-13 7:26 
I am using Visual Studio 2010 Pro, and have a unique issue that I'm hoping someone can help with. I overloaded the move operator = on a class, with the following code:
C++
template<class T>
MyClass<T> &MyClass<T>::operator =(MyClass &&other) {
    if (this != &other) {
        std::swap(m_Data , other.m_Data ); // T*
        std::swap(m_Size1, other.m_Size1); // size_t
        std::swap(m_Size2, other.m_Size2); // size_t
        std::swap(m_Size3, other.m_Size3); // size_t
        std::swap(m_Bool1, other.m_Bool1); // bool
        std::swap(m_Bool2, other.m_Bool2); // bool
    }
    return *this;
}

When I enter this method in the debugger, all of the fields of both *this and other are what I expect. In case it matters, the values are:
         *this     other
m_Data     0    0x15E4D2EC0
m_Size1    0        5041
m_Size2    0        5041
m_Size3    0         1
m_Bool1   true     false
m_Bool2   true      true

My expectation is that the calls to std::swap exchange the values of all the aforementioned fields. However, on the first call to swap, when I step into the function, I get that _Left = 0 and _Right = 0x7FEF5B07EDF. WTF? Why did the value of _Right change from 0x15E4D2EC0? Even more confusing, is that at the end of the function, _Left = 0x7FEF5B07EDF, _Right = 0, but upon returning, the value of other.m_Data has NOT changed to 0. Additionally, the following fields in the "other" object changed to the values indicated (after only executing the first std::swap):
             other
m_Data   0x7FEF5B07EDF (should be 0)
m_Size1    67251472    (should be 5041)
m_Size2        0       (should be 5041)
m_Size3    67257296    (should be 1)
m_Bool1      true      (should be false)
m_Bool2      true      (should be true)
WTF? Why does calling std::swap on a single field totally hose my entire object? It is as if the first call somehow changed the type of other. Can anyone shed some light onto what is happening here? Additionally, when the future calls of std::swap are executed (all but the first), they copy the value from other to *this, but don't change the value of other (for example, after executing std::swap(m_Size1, other.m_Size1), I would expect m_Size1 = 67251472 (which it does), and other.m_Size1 = 0 (it is still equal to 67251472). Thanks,
Sounds like somebody's got a case of the Mondays

-Jeff


modified 11-Dec-13 14:35pm.

AnswerRe: std::swap Corruption Pin
Skippums11-Dec-13 8:35
Skippums11-Dec-13 8:35 
QuestionQuestion About Threads Pin
AmbiguousName11-Dec-13 5:55
AmbiguousName11-Dec-13 5:55 
AnswerRe: Question About Threads Pin
jschell11-Dec-13 9:03
jschell11-Dec-13 9:03 
AnswerRe: Question About Threads Pin
Chris Losinger11-Dec-13 10:37
professionalChris Losinger11-Dec-13 10:37 
GeneralRe: Question About Threads Pin
Richard Andrew x6411-Dec-13 13:56
professionalRichard Andrew x6411-Dec-13 13:56 
AnswerRe: Question About Threads Pin
Albert Holguin12-Dec-13 4:25
professionalAlbert Holguin12-Dec-13 4:25 
QuestionRe: Question About Threads Pin
AmbiguousName12-Dec-13 4:58
AmbiguousName12-Dec-13 4:58 
QuestionAlways write to top of file Pin
Grahamfff11-Dec-13 1:16
Grahamfff11-Dec-13 1:16 
AnswerRe: Always write to top of file Pin
Richard MacCutchan11-Dec-13 1:53
mveRichard MacCutchan11-Dec-13 1:53 
GeneralRe: Always write to top of file Pin
Grahamfff11-Dec-13 2:33
Grahamfff11-Dec-13 2:33 
GeneralRe: Always write to top of file Pin
Richard MacCutchan11-Dec-13 2:38
mveRichard MacCutchan11-Dec-13 2:38 
GeneralRe: Always write to top of file Pin
Grahamfff11-Dec-13 4:04
Grahamfff11-Dec-13 4:04 
GeneralRe: Always write to top of file Pin
Richard MacCutchan11-Dec-13 4:57
mveRichard MacCutchan11-Dec-13 4:57 
GeneralRe: Always write to top of file Pin
enhzflep11-Dec-13 4:58
enhzflep11-Dec-13 4:58 
AnswerRe: Always write to top of file Pin
Eugen Podsypalnikov11-Dec-13 2:26
Eugen Podsypalnikov11-Dec-13 2:26 
QuestionRe: Always write to top of file Pin
David Crow11-Dec-13 5:15
David Crow11-Dec-13 5:15 
AnswerRe: Always write to top of file Pin
Grahamfff11-Dec-13 5:22
Grahamfff11-Dec-13 5:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.