C++ Q: What makes ‘Static’ local variables useful?

On page 53 in C++ Essentials by Sharam Hekmat, it reads

Static local variables are useful when we want the value of a local variable to persist across the calls to the function in which it appears. For example, consider an Errorfunction which keeps a count of the errors and aborts the program when thecount exceeds a preset limit:

void Error (char *message)
{
static int count = 0; // static local variable
if (++count > limit)
Abort(); //...
}

Well, I don’t get it. What does that mean?

Posted in C++ Study | Leave a comment

C++ question on Scope Operator

On page 50 in C++ Essentials by Sharam Hekmat, it gives an example

int error;
void Error (int error)
{
//…
if (::error != 0) // refers to global error
//…
}

in which error is a global variable and in function Error, error is redefined as a local variable. It says ::error should refer to the global error. But it does not work for me. The compiler gives an error message, saying ‘::error undeclared’. How to understand this?

Posted in C++ Study | Tagged | 1 Comment

C++ notes: <iostream> vs. <iostream.h>

Please refer to the following link for more info.
http://members.gamedev.net/sicrane/articles/iostream.html

my understanding:
<iostream> is for the new compiler and it should be followed by ‘using namespace std;’, like

#include<iostream>
using namespace std;

int main()
{
\\ body
}

 

Posted in C++ Study | Tagged | Leave a comment

Start up with C++

I am totally new to C++ and just learnt that there are lots of different compile+editor combinations for C++. Well, I just picked one, ‘dev C++’, which is recommended by others.

Dev C++ is a free ware. To download and install, please visit http://www.bloodshed.net/dev/devcpp.html .

Posted in C++ Study | Leave a comment

C++ study notes and questions blog

The purpose of the blog is to make a note on anything I will struggle with during my learning C++. I will publish some notes on my understanding and questions I will encounter. You are welcome to leave comments and answer my questions.

So far, I am reading C++ Essentials by Sharam Hekmat. This is a thin, compact book, recommended by XYF, who is the other member in out study group.

I also found some other recommendations from the web.

The following books are recommended; read them in mostly the order listed.

Another post

To get started I’d say you go with either C++ Primer from Lippman or Thinking in C++ from Bruce .Eckel

After that, get familiar with the STL.

Nicolai Josuttis

  • The C++ Standard Library – A Tutorial and Reference.

And I’ve never known a C++ developer who didn’t learn a lot from the books of both

Scott Meyers :

  • Effective C++
  • More Effective C++
  • Effective STL

and Herb Sutter:

  • Exceptional C++
  • More Exceptional C++
Posted in C++ Study | Leave a comment

Hello world!

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!

Posted in Personal | 1 Comment