Click here to Skip to main content
15,907,493 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Previous selection in listbox? Pin
Bob Stanneveld15-Apr-05 4:42
Bob Stanneveld15-Apr-05 4:42 
GeneralRe: Previous selection in listbox? Pin
David Crow15-Apr-05 5:22
David Crow15-Apr-05 5:22 
AnswerRe: Previous selection in listbox? Pin
Ravi Bhavnani14-Apr-05 7:05
professionalRavi Bhavnani14-Apr-05 7:05 
GeneralRe: Previous selection in listbox? Pin
Bob Stanneveld14-Apr-05 23:11
Bob Stanneveld14-Apr-05 23:11 
Questionmultiple windows in Visual Studio 7.0? Pin
IlanTal14-Apr-05 3:33
IlanTal14-Apr-05 3:33 
AnswerRe: multiple windows in Visual Studio 7.0? Pin
Chris Losinger14-Apr-05 4:40
professionalChris Losinger14-Apr-05 4:40 
GeneralGetParent() always returns NULL!! Pin
Dave_14-Apr-05 2:56
Dave_14-Apr-05 2:56 
General->Operator overloading in C++ Pin
Member 6822414-Apr-05 2:37
Member 6822414-Apr-05 2:37 
Hi all !

I would like to protect a standard C struct with a CRC in order to check if the structure contains valid information.

A wrote a small demo program with a standard C structure as member. If I read any element of the structure the checksum should be checked for correctness. If I write any element of the structure the checksum has to be recalculated. I would like to do that by overloading the -> operator.
In the demo program the call of the -> operator function works fine. However I have the problem to check if there is a Read- or Writeaccess. How can I check if an expression like
x->deviceData.HW_Version is used within a write or a read context ?

sincerly

ManfredSmile | :) Smile | :) Smile | :)

#include "stdafx.h"
#include <stdio.h>

// --- standard C structure ------------------------------
typedef
struct
{
int SW_Version ;
int HW_Version ;
unsigned long SerialNumber ;
} DeviceData ;

// --- class with CRC functionality ------------------------
class CCrc
{
public:
unsigned short crc ;
} ;

class CrcClass : public CCrc
{
public:
DeviceData deviceData ;

void CheckCrc() ;
CrcClass * operator->() ;
};

CrcClass * CrcClass::operator->()
{
CheckCrc() ;
return this;
};

void CrcClass::CheckCrc()
{
if( 1 ) // throw Exception for test
{
throw "Invalid Checksum !!!!\r\n" ;
}
};

int main(int argc, char * argv[])
{
CrcClass x ;

try
{
x->deviceData.HW_Version = 111 ;
x->deviceData.SW_Version = 222 ;
x->deviceData.SerialNumber = 333 ;

printf("%d", x->deviceData.HW_Version );
printf("%d", x->deviceData.SW_Version );
printf("%d", x->deviceData.SerialNumber );
}
catch( char * exMessage )
{
printf("%s", exMessage ) ;
}

return 0;
}
GeneralRe: -&gt;Operator overloading in C++ Pin
Maximilien14-Apr-05 3:12
Maximilien14-Apr-05 3:12 
GeneralRe: -&gt;Operator overloading in C++ Pin
Cedric Moonen14-Apr-05 3:23
Cedric Moonen14-Apr-05 3:23 
QuestionHow to start NT services in VC++ Pin
aloktambi14-Apr-05 2:24
aloktambi14-Apr-05 2:24 
AnswerRe: How to start NT services in VC++ Pin
ThatsAlok14-Apr-05 2:46
ThatsAlok14-Apr-05 2:46 
Questionhow to make random number generate fuction in vc++ Pin
aloktambi14-Apr-05 2:23
aloktambi14-Apr-05 2:23 
AnswerRe: how to make random number generate fuction in vc++ Pin
David Crow14-Apr-05 2:31
David Crow14-Apr-05 2:31 
AnswerRe: how to make random number generate fuction in vc++ Pin
ddmcr14-Apr-05 4:47
ddmcr14-Apr-05 4:47 
AnswerRe: how to make random number generate fuction in vc++ Pin
El Corazon14-Apr-05 5:18
El Corazon14-Apr-05 5:18 
GeneralFailed to register service during VC build Pin
pettink14-Apr-05 2:12
pettink14-Apr-05 2:12 
GeneralRe: Failed to register service during VC build Pin
Blake Miller14-Apr-05 4:28
Blake Miller14-Apr-05 4:28 
Generalconvert hex value to string Pin
Jangid14-Apr-05 1:54
Jangid14-Apr-05 1:54 
GeneralRe: convert hex value to string Pin
Bob Stanneveld14-Apr-05 3:34
Bob Stanneveld14-Apr-05 3:34 
GeneralRe: convert hex value to string Pin
CP Visitor14-Apr-05 4:28
CP Visitor14-Apr-05 4:28 
GeneralRe: convert hex value to string Pin
Blake Miller14-Apr-05 4:31
Blake Miller14-Apr-05 4:31 
GeneralRe: convert hex value to string Pin
itkid15-Apr-05 0:26
itkid15-Apr-05 0:26 
Generallinker error Pin
MilanZ14-Apr-05 0:53
MilanZ14-Apr-05 0:53 
GeneralRe: linker error Pin
David Crow14-Apr-05 2:29
David Crow14-Apr-05 2:29 

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.