Ask your own question, for FREE!
Computer Science 11 Online
OpenStudy (anonymous):

class C{ public: int f(int a){return x*a;} protected: int getX(){return x;} private: int x; }; cout<

OpenStudy (atlas):

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

OpenStudy (anonymous):

it has many errors

OpenStudy (anonymous):

parameters are not properly used in programms

OpenStudy (atlas):

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

OpenStudy (atlas):

@thangeram

OpenStudy (anonymous):

are u calling it in main or in the implementation file

OpenStudy (anonymous):

Int getX needs to be public. not protected.

OpenStudy (nethwa):

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.

OpenStudy (anonymous):

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 .

OpenStudy (anonymous):

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

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!