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

C / C++ / MFC

 
GeneralHelp! Pin
Anonymous9-Dec-04 13:09
Anonymous9-Dec-04 13:09 
GeneralRe: Help! Pin
toxcct9-Dec-04 21:54
toxcct9-Dec-04 21:54 
QuestionHow to do oldschool graphics in win Pin
mirex9-Dec-04 11:03
mirex9-Dec-04 11:03 
AnswerRe: How to do oldschool graphics in win Pin
Andrew Walker9-Dec-04 14:57
Andrew Walker9-Dec-04 14:57 
GeneralCompare from file or Compare from memory Pin
Anonymous9-Dec-04 10:41
Anonymous9-Dec-04 10:41 
GeneralRe: Compare from file or Compare from memory Pin
gamitech9-Dec-04 11:55
gamitech9-Dec-04 11:55 
General2nd Question - const_cast and mutable Pin
Malcolm Smart9-Dec-04 10:41
Malcolm Smart9-Dec-04 10:41 
GeneralRe: 2nd Question - const_cast and mutable Pin
Jack Puppy9-Dec-04 15:29
Jack Puppy9-Dec-04 15:29 
1) I've used mutables in one instance, for capturing statistical data in a test class...

<br />
void MyTestClass::PerformTest() const<br />
{<br />
   // Perform some test that shouldn't change the "important" member variables<br />
<br />
   // Here lies the mutable statistical members<br />
   if (Test was successful)<br />
     _successes++;<br />
   else<br />
     _failures++;<br />
}<br />


I also found an example in a book (Effective C++) of a String class that caches the string length each time the length member function is called using mutables:

<br />
.h<br />
--<br />
<br />
mutable bool lengthIsValid;<br />
mutable size_t dataLength;<br />
<br />
.cpp<br />
----<br />
<br />
size_t String::length() const<br />
{<br />
  if (!lengthIsValid) {<br />
    dataLength = strlen(data);    // now fine<br />
    lengthIsValid = true;         // also fine<br />
  }<br />
  return dataLength;<br />
}<br />


2) The only time I've ever had to use const_cast (not a pointer to const data though), is when I came across a 3rd party issue...

void MyClass::DoSomething(LPCTSTR lpszData)
{
Win32ApiCall(const_cast<LPTSTR>(lpszData));
}

The Win32 call wanted a LPTSTR, even though the string wasn't changed by the function. I don't know what you'd call it - the dreaded 3rd party design flaw?


Suspicious | :suss: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
GeneralRe: 2nd Question - const_cast and mutable Pin
Andrew Walker9-Dec-04 15:29
Andrew Walker9-Dec-04 15:29 
GeneralRe: 2nd Question - const_cast and mutable Pin
Henry miller10-Dec-04 6:22
Henry miller10-Dec-04 6:22 
Generalexcel automation with very hidden sheet Pin
pnpfriend9-Dec-04 10:38
pnpfriend9-Dec-04 10:38 
QuestionWhat is best Exe 2 Exe protocol? Pin
Malcolm Smart9-Dec-04 10:34
Malcolm Smart9-Dec-04 10:34 
AnswerRe: What is best Exe 2 Exe protocol? Pin
Alex Korchemniy9-Dec-04 11:05
Alex Korchemniy9-Dec-04 11:05 
AnswerRe: What is best Exe 2 Exe protocol? Pin
Renjith Ramachandran9-Dec-04 19:13
Renjith Ramachandran9-Dec-04 19:13 
AnswerRe: What is best Exe 2 Exe protocol? Pin
Henry miller10-Dec-04 6:31
Henry miller10-Dec-04 6:31 
GeneralVariable width fonts and GetTextExtent in CEdit Pin
bob169729-Dec-04 8:47
bob169729-Dec-04 8:47 
GeneralRe: Variable width fonts and GetTextExtent in CEdit Pin
bob169729-Dec-04 11:01
bob169729-Dec-04 11:01 
GeneralHTML Help window Message handling Pin
Member 15760289-Dec-04 8:44
Member 15760289-Dec-04 8:44 
Generalswap bytes in a file Pin
Anonymous9-Dec-04 8:09
Anonymous9-Dec-04 8:09 
GeneralRe: swap bytes in a file Pin
David Crow9-Dec-04 10:24
David Crow9-Dec-04 10:24 
GeneralRe: swap bytes in a file Pin
Anonymous9-Dec-04 10:29
Anonymous9-Dec-04 10:29 
GeneralSerial Communication ... problems! Pin
PPatrickFFM9-Dec-04 5:48
PPatrickFFM9-Dec-04 5:48 
GeneralRe: Serial Communication ... problems! Pin
bob169729-Dec-04 9:43
bob169729-Dec-04 9:43 
GeneralAdding controls to ActiveX project Pin
greekgoddj9-Dec-04 5:06
greekgoddj9-Dec-04 5:06 
GeneralSymbian OS Pin
Anonymous9-Dec-04 5:00
Anonymous9-Dec-04 5:00 

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.