Search

Sponsored Links

Meta

Categories

Archives

Recent Posts

RSS Feeds

08
Dec

C++ Advanced Tutorial - Lesson 11

Related Blog Items

Please refer Lesson 10..

11. SOME INDIVIDUAL TOPICS
11.1 DOS Keyboard Characteristics
11.2 Detach Method for Wrapper Classes

11. SOME INDIVIDUAL TOPICS

11.1 DOS Keyboard Characteristics

When any key on the keyboard is pressed, a parameter in the operating system is set, and this parameter can be checked through method kbhit( ) in . Then we can get this character through method getch in . Method getch returns one char at a time. If the key can be represented in ASCII, the ASCII code of the character is returned. But many keys cannot be represented in ASCII, for example the F1 key and the PageDown key. When they have been pressed, first a zero is returned, then the next value we get will tell us which key it was.

11.2 Detach Method for Wrapper Classes

Some wrapper classes has a pointer to another dynamic object. In its destructor it usually delete that object to free the space. However, if some one calls its “get” method which returns this pointer to the outside world, then the dynamic object is taken care of by another program and should be “detached” from the wrapper class, so that the destructor is no longer responsible to delete that dynamic object.:

class Person 
{
private:
  char * m_strName;
 
public:
  Person(char * name = NULL) : m_strName(name) 
  {}
 
  ~Person() 
  {  
    if(m_strName != 0) 
      delete m_strName; 
  }
 
  char * Detach() 
  {  
    char * temp;
    temp = m_strName;
    m_strName = 0; 
    return temp;
  }
}

Popularity: 40%

You need to log on to convert this article into PDF


Related Blog Items

No Comments

No comments yet.

Leave a comment

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image