Find the errors in the following class and explain how to correct them:

```
class Example
{
public:
Example( int y = 10 )
: data( y )
{
// empty body
} // end Example constructor
int getIncrementedData() const
{
return data++;
} // end function getIncrementedData
static int getCount()
{
cout << "Data is " << data << endl;
return count;
} // end function getCount
private:
int data;
static int count;
}; // end class Example
```

Error: The class definition for Example has two errors. The first occurs in function getIncrementedData. The function is declared const, but it modifies the object.
Correction: To correct the first error, remove the const keyword from the definition of getIncrementedData.
Error: The second error occurs in function getCount. This function is declared static, so it isn’t allowed to access any non-static member (i.e., data) of the class.
Correction: To correct the second error, remove the output line from the getCount definition.

Computer Science & Information Technology

You might also like to view...

The ________ numbering system uses base 2

Fill in the blank(s) with correct word

Computer Science & Information Technology

With a RAID 10 how much storage would I have available if I used 4 drives each with 10 GB space.

A. 10 B. 20 C. 30 D. 40

Computer Science & Information Technology