Complete listing of Errors01.cpp, Listing 1

/*File:  Errors01.cpp
This c++ program illustrates a syntax error that
produces the following compiler error.  Note that
line breaks were manually inserted into the error
message to force it to fit into this narrow
publication format.

C:\jnk\Errors01.cpp(29) : error C2228: 
left of '.doSomething' 
must have class/struct/union type


#include <iostream>
using namespace std;

class Errors01{ 
  static void classMain(){
    //Instantiate an object of the Errors01 class 
    // and save its reference in a pointer 
    // variable.
    Errors01* ptrToObject = new Errors01();
    //Now invoke the instance function named 
    // doSomething belonging to the object.
    // ptrToObject -> doSomething();//correct
  }//End classMain function

  //An instance function of the Errors01 class
  void doSomething(){
    cout << "Hello World\n";
  }//end doSomething function
};//End Errors01 class

int main(){
  return 0;
}//end main

Listing 1