Complete listing of Errors03.cpp, Listing 3
/*File: Errors03.cpp
This C++ program illustrates a logic error. The
intent was for the program to display the
following text:
Hello World
However, a programming logic error causes the
program to display the following text instead:
Goodbye Cruel World
************************************************/
#include <iostream>
using namespace std;
class Errors03{
public:
static void classMain(){
//Instantiate an object in dynamic memory
// and save its reference in a pointer
// variable.
Errors03* ptrToObject = new Errors03();
//Invoke an instance function on the object.
ptrToObject -> doSomething();
}//End classMain function
//-------------------------------------------//
//An instance function of the Errors03 class
void doSomething(){
cout << "Goodbye Cruel World\n";
}//end doSomething function
};//End Errors03 class
//---------------------------------------------//
int main(){
Errors03::classMain();
return 0;
}//end main
Listing 3
|