Hello everyone,
I'm so struggling with the following 4 questions.
I'm not sure if I get the question right too.. (what does it mean by public/ private methods??)
could you kindly suggest the answers and explain why?
1.What portions of a class Foo can be called by a public method of the class Foo?
- is this asking what parts of the class (public, protected or private) can be called by a function under public in class Foo?? and will only public parts be called?
2.What portions of a class Foo can be called by a private method of the class Foo?
- is this asking what parts can be called by a private function? and this function can access to both public and private?
3.What portions of a class Foo can be called by using the object f by the operation void Bar::b( Foo f ) ?
- because a function of another class uses the object f as the argument, will it only access to the public portions?
4. What portions of a class Foo can be called by using the object f by the operation void Bar::c( const Foo & f ) ?
- I have no idea about this question..... :(
i think this is a solution for the questions but i don't get it
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
Class Foo
{
int getK( );
Public:
int getI( );
int getJ( ) const;
};
Void foobar( Foo f )
{
f.getK( ); /// illegal
f.getI( );
f.getJ( );
}
Void bar( const Foo & f )
{
f.getI( ); //// illegal bark at us
f.getJ( ); //// work
}
| |