Click here to Skip to main content
15,917,642 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to detect all the hard disks or mycomputer? Pin
l a u r e n20-Apr-02 6:54
l a u r e n20-Apr-02 6:54 
AnswerRe: Ignore my previous post Pin
Phlegm20-Apr-02 7:13
Phlegm20-Apr-02 7:13 
GeneralRe: Ignore my previous post Pin
Paul M Watt20-Apr-02 8:03
mentorPaul M Watt20-Apr-02 8:03 
GeneralRe: Ignore my previous post Pin
20-Apr-02 22:12
suss20-Apr-02 22:12 
AnswerRe: Ignore my previous post Pin
Phlegm20-Apr-02 7:14
Phlegm20-Apr-02 7:14 
AnswerRe: How to detect all the hard disks or mycomputer? Pin
Michael Dunn20-Apr-02 7:28
sitebuilderMichael Dunn20-Apr-02 7:28 
AnswerRe: How to detect all the hard disks or mycomputer? Pin
Jack Handy20-Apr-02 9:59
Jack Handy20-Apr-02 9:59 
GeneralAn error with 'delete' Pin
Rickard Andersson2020-Apr-02 5:40
Rickard Andersson2020-Apr-02 5:40 
When the object of my class (see below) have done its work my app crashes!
And the debuger says there is in operator 'delete' an expression error: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse). I have allocated memory in both my constructors and deleting it corectly... haven't I?

My class:

class CScoreData
{
// Public member functions
public:
CScoreData(char* player, int score);
CScoreData();
~CScoreData();

void FillData(char* player, int score);

char* GetPlayer(){ return m_chPlayer; }
int GetScore(){ return m_nScore; }

// Operator overloading
public:
CScoreData& operator=(CScoreData& sd);

// Member data
private:
char* m_chPlayer; // Player name
int m_nScore; // Player score
};

CScoreData::CScoreData()
{
m_chPlayer = new char[MAX_SD_BUFFER];
m_nScore = 0;
}

CScoreData::CScoreData(char* player, int score)
{
m_chPlayer = new char[MAX_SD_BUFFER];
FillData(player,score);
}

CScoreData::~CScoreData()
{
delete [] m_chPlayer;
}

void CScoreData::FillData(char* player, int score)
{
strcpy(m_chPlayer, player);
m_nScore = score;
}

CScoreData& CScoreData::operator=(CScoreData& sd)
{
if(this == &sd)
return *this;

strcpy(m_chPlayer, sd.GetPlayer());
m_nScore = sd.GetScore();
return *this;
}

int main()
{
CScoreData sd;
sd.FillData("Testar att vara cool",120000);

ofstream fout("file.osh",ios::binary);
if(!fout)
return 1;

fout.write((char*)&sd, sizeof(sd));
fout.close();

/////////////////////////////////////////////
/////////////////////////////////////////////

CScoreData sd2;

ifstream fin("file.osh", ios::binary);
if(!fin)
return 1;

fin.read((char*)&sd2, sizeof(sd2));
fin.close();

cout << sd2.GetPlayer() << "\n" << sd2.GetScore() << endl;

return 0;
}



------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!

------------------------------------
GeneralRe: An error with 'delete' Pin
Paul M Watt20-Apr-02 6:22
mentorPaul M Watt20-Apr-02 6:22 
GeneralRe: An error with 'delete' Pin
Rickard Andersson2020-Apr-02 11:29
Rickard Andersson2020-Apr-02 11:29 
GeneralRe: An error with 'delete' Pin
Paul M Watt20-Apr-02 12:06
mentorPaul M Watt20-Apr-02 12:06 
GeneralRe: An error with 'delete' Pin
Rickard Andersson2020-Apr-02 12:45
Rickard Andersson2020-Apr-02 12:45 
GeneralRemote Logon! Pin
hph20-Apr-02 5:13
hph20-Apr-02 5:13 
GeneralRe: Remote Logon! Pin
Mike Nordell21-Apr-02 23:02
Mike Nordell21-Apr-02 23:02 
GeneralactivX in c++ Pin
20-Apr-02 4:51
suss20-Apr-02 4:51 
GeneralRe: activX in c++ Pin
Tunococ20-Apr-02 5:04
Tunococ20-Apr-02 5:04 
GeneralRe: activX in c++ Pin
Imran Farooqui20-Apr-02 5:07
Imran Farooqui20-Apr-02 5:07 
GeneralRe: activX in c++ Pin
20-Apr-02 5:16
suss20-Apr-02 5:16 
QuestionWhat happens when the user close a control bar by clicking the x button on the top right corner? Pin
Tunococ20-Apr-02 4:37
Tunococ20-Apr-02 4:37 
AnswerRe: What happens when the user close a control bar by clicking the x button on the top right corner? Pin
Shog920-Apr-02 5:05
sitebuilderShog920-Apr-02 5:05 
GeneralRe: What happens when the user close a control bar by clicking the x button on the top right corner? Pin
Tunococ20-Apr-02 5:12
Tunococ20-Apr-02 5:12 
GeneralDisplaying Bitmap file in Dialog box Pin
malf20-Apr-02 4:34
malf20-Apr-02 4:34 
GeneralRe: Displaying Bitmap file in Dialog box Pin
Tunococ20-Apr-02 4:59
Tunococ20-Apr-02 4:59 
GeneralCreateProcessWithLogonW() Pin
hph19-Apr-02 23:55
hph19-Apr-02 23:55 
GeneralRe: CreateProcessWithLogonW() Pin
l a u r e n20-Apr-02 0:36
l a u r e n20-Apr-02 0:36 

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.