Click here to Skip to main content
15,921,905 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: how to check that database was corrupted or not??? Pin
David Crow8-Jun-11 3:04
David Crow8-Jun-11 3:04 
AnswerRe: how to check that database was corrupted or not??? Pin
jschell8-Jun-11 9:02
jschell8-Jun-11 9:02 
QuestionSetting RTL for a window? Pin
Hans Dietrich7-Jun-11 16:27
mentorHans Dietrich7-Jun-11 16:27 
AnswerRe: Setting RTL for a window? Pin
Code-o-mat7-Jun-11 21:53
Code-o-mat7-Jun-11 21:53 
AnswerRe: Setting RTL for a window? Pin
Hans Dietrich8-Jun-11 4:00
mentorHans Dietrich8-Jun-11 4:00 
GeneralRe: Setting RTL for a window? Pin
Code-o-mat8-Jun-11 6:08
Code-o-mat8-Jun-11 6:08 
GeneralRe: Setting RTL for a window? Pin
Code-o-mat9-Jun-11 6:56
Code-o-mat9-Jun-11 6:56 
QuestionWin32 Buttons, which is which? [solved] Pin
Groulien7-Jun-11 8:56
Groulien7-Jun-11 8:56 
AnswerRe: Win32 Buttons, which is which? [solved] Pin
Albert Holguin7-Jun-11 14:34
professionalAlbert Holguin7-Jun-11 14:34 
AnswerRe: Win32 Buttons, which is which? [solved] Pin
Tarmo Kalda9-Jun-11 0:03
Tarmo Kalda9-Jun-11 0:03 
QuestionHelp with reading Window titles and text in C sharp Pin
turbosupramk37-Jun-11 4:56
turbosupramk37-Jun-11 4:56 
AnswerRe: Help with reading Window titles and text in C sharp Pin
Albert Holguin7-Jun-11 5:36
professionalAlbert Holguin7-Jun-11 5:36 
GeneralRe: Help with reading Window titles and text in C sharp Pin
turbosupramk37-Jun-11 6:13
turbosupramk37-Jun-11 6:13 
GeneralRe: Help with reading Window titles and text in C sharp Pin
Albert Holguin7-Jun-11 6:23
professionalAlbert Holguin7-Jun-11 6:23 
QuestionLoadInstanceString failed in Windows7 Operating System. Pin
janaswamy uday7-Jun-11 0:10
janaswamy uday7-Jun-11 0:10 
AnswerRe: LoadInstanceString failed in Windows7 Operating System. Pin
Richard MacCutchan7-Jun-11 0:21
mveRichard MacCutchan7-Jun-11 0:21 
GeneralRe: LoadString failed in Windows7 Operating System. [modified] Pin
janaswamy uday7-Jun-11 0:42
janaswamy uday7-Jun-11 0:42 
GeneralRe: LoadString failed in Windows7 Operating System. Pin
giangian7-Jun-11 0:50
giangian7-Jun-11 0:50 
GeneralRe: LoadString failed in Windows7 Operating System. Pin
janaswamy uday7-Jun-11 0:57
janaswamy uday7-Jun-11 0:57 
QuestionRe: LoadString failed in Windows7 Operating System. Pin
David Crow7-Jun-11 2:52
David Crow7-Jun-11 2:52 
GeneralRe: LoadString failed in Windows7 Operating System. Pin
Richard MacCutchan7-Jun-11 0:57
mveRichard MacCutchan7-Jun-11 0:57 
GeneralRe: LoadString failed in Windows7 Operating System. Pin
Richard MacCutchan7-Jun-11 0:59
mveRichard MacCutchan7-Jun-11 0:59 
QuestionC++ Question Pin
Software20076-Jun-11 17:18
Software20076-Jun-11 17:18 
I saw the following question as an interview question on one of the sites, Can anyone see if I answered correctly? Thanks
// The code compiles but it has some problems and
// inefficiencies.  Describe what its trying to do, then
// comment on the bugs and how to fix them.  Also please give suggestions on
// how to improve the method. Name relevant softwareprinciples



bool Item::SetInt( INT_STAT key, int val, UpdateType update )
{

  m_Something->SetInt( key, val );

  int i;
  bool retval;

  byte* buffer = new byte[ 256 ];

  if ( update & No_UpdateType == No_UpdateType )
  {
    return false;
  }


  if ( update & Private_UpdateType == Private_UpdateType )
  {

    for ( i = 0; i < m_numEvents; ++i )
      {
        if ( m_eventFilter[i] == key )
		{
          retval = true;
        } 
		else 
		{
          retval = false;
        }
      }

    if ( retval ) {
      SendPrivateEvent( buffer, key, val );
    }
  }


  if ( update & Public_UpdateType == Public_UpdateType ) 
  {
  
    for ( i = 0; i < m_numEvents; ++i )
      {
         if ( m_eventFilter[i] == key ) 
		 {
           retval = true;
         }
		 else 
		 {
           retval = false;
         }
      }

    if ( retval ) 
	{
      SendPublicEvent( buffer, key, val );
    }
  }


  delete buffer;

  return retval;
}

My Answers:
//This function returns a boolean (true or false);
// if No_UpdateType, this function quits and exits with a return value of false
// if Private_UpdateType || public_UpdateType, we will check to see if the key
//passed in exists in the m_eventFilter Array, if it does, we will "sendPublicNetworkEvent" 
//or "sendPrivateNetworkEvent" respectively

//////////////////////////////////
//Inefficiencies and Suggestions:
//////////////////////////////////
//buffer was never initialized
//buffer in this example is passed as an argumeatnt, but was never implemented (no data assigned to it)
//If the buffer meant to be used as an output, it should have been passed as a refernce (&buffer)

//In the if conditional statements, update is being used as a boolean, to evaluate a boolean expresion with
//a mask - not good practise.

//if m_eventFilter is a larger array, it makes the search for the key expensive,
//it would be more efficient to use a Map for look up
//worst case scenario, if array had to be used, I would break out of the loop once key is found.

//redundant repetitive code

//This switch logic is popular in C++ design patterns, in designs where code reacts to the change of 
//object state, State Design Patterns as well as Observer patterns are ideal.
//So, when updateObjectType changes, the appropriate handler can be called at runtime.

AnswerRe: C++ Question Pin
Niklas L7-Jun-11 2:00
Niklas L7-Jun-11 2:00 
GeneralRe: C++ Question Pin
Stefan_Lang7-Jun-11 2:05
Stefan_Lang7-Jun-11 2:05 

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.