Click to See Complete Forum and Search --> : What is wrong with this code???


Bobby2001
April 23rd, 2005, 01:29 PM
Please take a look at the simple console app code below:

#include "stdafx.h"

#using <mscorlib.dll>

using namespace System;

typedef struct {
unsigned long checkSum;
} DATALOG_FILE;

class CLogConfig
{
public:
CLogConfig();
~CLogConfig();

public:
DATALOG_FILE log [16];
};

CLogConfig::CLogConfig()
{
}

CLogConfig::~CLogConfig()
{
}

int _tmain()
{
CLogConfig m_LogConfig;

m_LogConfig.log[0].checkSum = 123 ;
m_LogConfig.log[5].checkSum = 456 ;
m_LogConfig.log[9].checkSum = 789 ;

return 0;
}

I set breakpoint at the beginning of main procedure, run this program in
VS.NET 2003 debugger and debug it step by step. I add m_LogConfig.log[0].checkSum variable to watch window and observe the following:

The first statement works fine and value 123 assigned to
m_LogConfig.log[0].checkSum

However the second and third statement due to unknown reasons do not assign
values 456 and 789.

Even when I open QuickWatch window and try to change value of variable
m_LogConfig.log[5].checkSum the error dialog "Cannot Change Value" pops up.

Can anyone explain what is going wrong with this code?

Thank you

cilu
April 25th, 2005, 08:08 AM
Your code runs perfectly. What are you taking about? :confused: 0, 5 and 9 indexed elements of log are set to those values, the other 13 are left initialized.