What is wrong with the following code? class classA { protected: void setX(int a
ID: 3905694 • Letter: W
Question
What is wrong with the following code?
class classA
{
protected:
void setX(int a); // Line 1
//postcondition: x = a; // Line 2
private: // Line 3
int x; // Line 4
};
.
.
.
int main()
{
classA aObject; // Line 5
aObject.setX(4); // Line 6
return 0; // Line 7
}
Explanation / Answer
error here is protected members or members of class can be accessed by members of same class and they cannot be accessed by object references. Error here is we are trying to access setX() of classA using object of that clss which was not possible. That was the error.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.