class portions that will be called by each method

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
}
In a class Public methods can be accessed from outside the class. Private methods can only be accessed within the class. Classes by defualt are private so in your above code int getK( ); is private and int getI( ); and int getJ( ) const; are public.
http://www.cplusplus.com/doc/tutorial/classes/


1.What portions of a class Foo can be called by a public method of the class Foo?
any of the methods can be called within class foo.

2. What portions of a class Foo can be called by a private method of the class Foo?
any of the methods can be called within class foo.

3. What portions of a class Foo can be called by using the object f by the operation void Bar::b( Foo f ) ?
only the public ones

4. What portions of a class Foo can be called by using the object f by the operation void Bar::c( const Foo & f ) ?
not sure about this one, but I believe it's also only the public ones

Hope this at least helps
Last edited on
4. What portions of a class Foo can be called by using the object f by the operation void Bar::c( const Foo & f ) ?

Only const-qualified, public members of Foo. In your example, only getJ().
Last edited on
thank you all!! all make sense :)
Topic archived. No new replies allowed.