Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Shahan03

class C{ public: int f(int a){return x*a;} protected: int getX(){return x;} private: int x; }; cout<<objC.getX(); //ERROR : C::getX is //unaccessible Why?

  • one year ago
  • one year ago

  • This Question is Closed
  1. atlas
    Best Response
    You've already chosen the best response.
    Medals 0

    I am not really into programming.......but it seems ok to me

    • one year ago
  2. thangeram
    Best Response
    You've already chosen the best response.
    Medals 0

    it has many errors

    • one year ago
  3. thangeram
    Best Response
    You've already chosen the best response.
    Medals 0

    parameters are not properly used in programms

    • one year ago
  4. atlas
    Best Response
    You've already chosen the best response.
    Medals 0

    @thageram I believe he did not write the complete program to save tedious typing

    • one year ago
  5. atlas
    Best Response
    You've already chosen the best response.
    Medals 0

    @thangeram

    • one year ago
  6. REMAINDER
    Best Response
    You've already chosen the best response.
    Medals 0

    are u calling it in main or in the implementation file

    • one year ago
  7. eszeikial
    Best Response
    You've already chosen the best response.
    Medals 0

    Int getX needs to be public. not protected.

    • one year ago
  8. NeThWa
    Best Response
    You've already chosen the best response.
    Medals 2

    The protected-flag only allows the Object itself and its following generations (classes, which extend this class, inheritance) to access the method. I'm not familiar with C (i guess its C) but for me it looks like thats your problem. Change it to public and it maybe it'll work.

    • one year ago
  9. sonymol
    Best Response
    You've already chosen the best response.
    Medals 0

    if any data member or member function is declared protected they will be accessible only in the class itself and the inherited class .Further accessibility will depend on the type of inheritance i.e public ,private etc.. To sort this out just make int getX() function public . I suppose that the function cout<<objC.getX(); is written in the main() or in a member function after creating objC .

    • one year ago
  10. thangeram
    Best Response
    You've already chosen the best response.
    Medals 0

    the value of getx is protected in this program there is parameters x is used to pass the value of x but the value of x is private so main cannot execute it he should change it public

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.