The following is a definition of class Example:
```
class Example {
public:
Example(int y = 10) : data(y) { }
int getIncrementedData() const {
return ++data;
}
static int getCount() {
cout << "Data is " << data << endl;
return count;
}
private:
int data;
static int count;
};
```
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. [Note: It would also be appropriate to rename this member
function, as get functions are typically const member functions.]
Error: The second error occurs in function getCount. This function is declared static,
so it’s not allowed to access any non-static class member (i.e., data).
Correction: To correct the second error, remove the output line from the getCount definition.
You might also like to view...
Objects created in other programs cannot be inserted into Word documents
Indicate whether the statement is true or false
When working with a chart, you click the ________ to display the CHART TOOLS
Fill in the blank(s) with the appropriate word(s).