Click here to Skip to main content
16,005,169 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: right-aligned image button in list control Pin
denyi0129-Mar-06 3:49
denyi0129-Mar-06 3:49 
Generalright-aligned image button in list control Pin
denyi0128-Mar-06 10:16
denyi0128-Mar-06 10:16 
GeneralRe: right-aligned image button in list control Pin
Laxman Auti28-Mar-06 17:27
Laxman Auti28-Mar-06 17:27 
QuestionCxImage - again - pDib question Pin
Vaclav28-Mar-06 10:01
Vaclav28-Mar-06 10:01 
AnswerRe: CxImage - again - pDib question Pin
Joel Lucsy29-Mar-06 7:17
Joel Lucsy29-Mar-06 7:17 
QuestionProblem overloading = operator Pin
bilbobaggio28-Mar-06 9:59
bilbobaggio28-Mar-06 9:59 
AnswerRe: Problem overloading = operator Pin
David Crow28-Mar-06 10:36
David Crow28-Mar-06 10:36 
GeneralRe: Problem overloading = operator Pin
bilbobaggio28-Mar-06 21:17
bilbobaggio28-Mar-06 21:17 
ok, sorry for not indenting and explaining myself properly. i have the missing semicolon and am using delete []. when i run the program. the values from temp2 get copied to temp1 and this gets displayed. but then when the program exits i get a 'Debug Assertion failed error - file: dbgheap.d, line:1017,
Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)

When I debug the application I see that the A dtor gets called after the assignment operation which removes the reference to the array data. So when the program exits and the destructor is called again it gives an error. But i dont know why this is happening or how to overcome it. here is my code sample

extern int y;

class A {

private:

    int* data;

public:

    A() { data = new int[5]; for (int i=0; i<5; i++) data[i]=y+i; }
    ~A() { delete [] data; cout<<"a dtor"<<endl; }

    A& operator= (const A a);

    friend ostream& operator<< (ostream& out, const A &a);
};

A& A::operator =(const A a)
{
    if (this == &a)
        return *this;

    for (int i=0; i<5; i++)
        data[i] = a.data[i];

    return *this;
}

ostream& operator<< (ostream& out, const A &a)
{
    for (int i=0; i<5; i++)
        out << a.data[i] << " ";

    return out;
}


then the main

void main()
{
    y=1;
    A temp1; // temp1 = {1,2,3,4,5};
    y++;
    A temp2; // temp2 = {2,3,4,5,6};

    cout << temp1 << endl;
    cout << temp2 << endl;

    temp1=temp2;

    cout << temp1 << endl;
} // error happens here


the program output is as follows
1 2 3 4 5
2 3 4 5 6
a dtor
2 3 4 5 6
then the error.
AnswerRe: Problem overloading = operator Pin
Roger Stoltz28-Mar-06 21:30
Roger Stoltz28-Mar-06 21:30 
GeneralRe: Problem overloading = operator Pin
David Crow29-Mar-06 2:53
David Crow29-Mar-06 2:53 
GeneralRe: Problem overloading = operator Pin
Roger Stoltz29-Mar-06 3:02
Roger Stoltz29-Mar-06 3:02 
AnswerRe: Problem overloading = operator Pin
Stephen Hewitt28-Mar-06 11:40
Stephen Hewitt28-Mar-06 11:40 
QuestionINT_PTR question Pin
yellowine28-Mar-06 9:29
yellowine28-Mar-06 9:29 
AnswerRe: INT_PTR question Pin
David Crow28-Mar-06 10:39
David Crow28-Mar-06 10:39 
AnswerRe: INT_PTR question Pin
Ștefan-Mihai MOGA29-Mar-06 0:00
professionalȘtefan-Mihai MOGA29-Mar-06 0:00 
QuestionHow to use IMediaSeeking::setpositions? Pin
yongwpi28-Mar-06 9:10
yongwpi28-Mar-06 9:10 
QuestionSir , Can Any one help me in knowing why it is not possible to Split a StaticSplitter More than 16rows and 16Cols? Pin
CodeVarma28-Mar-06 9:05
CodeVarma28-Mar-06 9:05 
QuestionRe: Sir , Can Any one help me in knowing why it is not possible to Split a StaticSplitter More than 16rows and 16Cols? Pin
David Crow28-Mar-06 9:08
David Crow28-Mar-06 9:08 
AnswerRe: Sir , Can Any one help me in knowing why it is not possible to Split a StaticSplitter More than 16rows and 16Cols? Pin
Waldermort28-Mar-06 9:49
Waldermort28-Mar-06 9:49 
GeneralRe: Sir , Can Any one help me in knowing why it is not possible to Split a StaticSplitter More than 16rows and 16Cols? Pin
David Crow28-Mar-06 10:13
David Crow28-Mar-06 10:13 
QuestionActiveX Control wrapper classes derived from CWnd and LPDISPATCH Pin
a_day28-Mar-06 9:01
a_day28-Mar-06 9:01 
AnswerRe: ActiveX Control wrapper classes derived from CWnd and LPDISPATCH Pin
Sheng Jiang 蒋晟28-Mar-06 15:51
Sheng Jiang 蒋晟28-Mar-06 15:51 
QuestionHCURSOR, animated or static? (Repost) Pin
PJ Arends28-Mar-06 8:57
professionalPJ Arends28-Mar-06 8:57 
AnswerRe: HCURSOR, animated or static? (Repost) Pin
Waldermort28-Mar-06 9:39
Waldermort28-Mar-06 9:39 
GeneralRe: HCURSOR, animated or static? (Repost) Pin
PJ Arends28-Mar-06 10:12
professionalPJ Arends28-Mar-06 10:12 

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.