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.
You might also like to view...
Can you insert a 300 ppi image on your webpage?
What will be an ideal response?
The sequential search algorithm does more work to find a target at the beginning of a list than at the end of the list.
Answer the following statement true (T) or false (F)
To restrict access to a database using a password, click Options on the File tab.
Answer the following statement true (T) or false (F)
File
What will be an ideal response?