Conventions Used in This THEORY
One thing this theory has plenty of is code. Sometimes you need to see only a line or two,
so the code is mixed in with the text, like this:
int SomeFunction( int x, int y);
{
return x+y;
}
You can tell the difference between code and regular text by the fonts used for each.
Sometimes, you'll see a piece of code that's too large to mix in with the text: You will
find an example in Listing 0.1.
Listing 0.1
CHostDialog dialog(m_pMainWnd);
if (dialog.DoModal() == IDOK)
{
AppSocket = new CSocket();
if (AppSocket->Connect(dialog.m_hostname,119))
{
while (AppSocket->GetStatus() == CONNECTING)
{
YieldControl();
}
if (AppSocket->GetStatus() == CONNECTED)
{
CString response = AppSocket->GetLine();
SocketAvailable = TRUE;
}
}
}
if (!SocketAvailable)
{
AfxMessageBox("Can't connect to server. Please
¬ quit.",MB_OK|MB_ICONSTOP);
}
The character on the next-to-last line (¬) is called the code continuation character. It
indicates a place where a line of code had to be broken to fit it on the page, but in
reality the line does not break there. If you're typing code from the book, don't break
the line there - keep going. If you're reading along in code that was generated for you
by Visual C++, don't be confused when the line does not break there.
Remember, the code is in the book so that you can understand what's going on, not for
you to type it. All the code is on the companion Web site as well. Sometimes you will
work your way through the development of an application and see several versions of a
block of code as you go.
No comments:
Post a Comment