Double free or corruption faststop

1
2
3
4
type& objecttype :: operator=(object& var){

    this->name=var.name //type string
}


getting error

double free or corruption faststop crash...even though program output is ok
Last edited on
Please edit your post and make sure your code is [code]between code tags[/code] so that it has syntax highlighting and line numbers, as well as proper indentation.

The function you posted has a return type but does not contain a return statement. You probably meant to add return *this; - it is a common mistake that I often make myself.
But Even after adding return *this, i get same error

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <string>
#include "ScoreKeeper.h"

using namespace std;

ScoreKeeper::ScoreKeeper(string subName, int numberOfMarks){

    numberOfScores=numberOfMarks;
    listScores=new float[numberOfScores];

    name=subName;
    for(int i=0;i<numberOfScores;i++){

        cout<<"Enter Mark " <<i+1<<" : ";
        cin>>listScores[i];

        while(listScores[i]<0 || listScores[i]>100)
            {
                cout<<"Enter between 0-100: ";
                cin.clear();
                cin.ignore();
                cin>>listScores[i];
            }
        cout<<"Enter Success"<<endl;

    }

}
ScoreKeeper::ScoreKeeper(){

    listScores=NULL;

}
ScoreKeeper::~ScoreKeeper(){


        delete [] listScores;
        listScores=NULL;
}

ostream& operator<<(ostream& out, ScoreKeeper& score){

    out<<"Name: "<<score.name<<endl;
    out<<"Number of marks: "<<score.numberOfScores<<endl;
    for(int i=0;i<score.numberOfScores;i++)
        out<<"Score "<<i+1<<" "<<score.listScores[i]<<endl;

    return out;
}
ScoreKeeper& ScoreKeeper::operator=( const ScoreKeeper& score){

    this->name=score.name;
    this->numberOfScores=score.numberOfScores;
    this->listScores=score.listScores;
    return *this;

}
Last edited on
Use your IDE's debugger to isolate which line the crash is happening on.
Topic archived. No new replies allowed.