Ans2)data member and member function of a class are the property of it's
objects/

>so the print function is a also a property of pointer 'pa' .

On 6/18/08, manav singh <[EMAIL PROTECTED]> wrote:
>
>   ans1) By default, all members of a class declared with the class
> keyword have private access for all its members. Therefore, any member
> that is declared before one other class specifier automatically has
> private access. thats why your code is producing error if u comment the
> public keyword
>
> ans2)who says that pa is pointing anything.It is pointing to somewhere. but
> you see it can create problems in further program.
> --- On Wed, 6/18/08, frankzhu_2001 <[EMAIL 
> PROTECTED]<frank.zhu.mingyu%40gmail.com>>
> wrote:
> From: frankzhu_2001 <[EMAIL PROTECTED]<frank.zhu.mingyu%40gmail.com>
> >
> Subject: [c-prog] class composition
> To: [email protected] <c-prog%40yahoogroups.com>
> Date: Wednesday, June 18, 2008, 7:56 PM
>
> Hi,
>
> I have two questions,
>
> 1. The following program will not compile if the 'public' is not
>
> defined. why?
>
> 2. Since pa is pointed to nowhere, is it a safe to use pa without
>
> the instanciate the class a?
>
> thanks,
>
> --- code starts here ---
>
> #include<iostream>
>
> using namespace std;
>
> class a{
>
> public:
>
> void print(void) { cout << "a print\n";}
>
> };
>
> class b{
>
> public: // error if this line is commented out.
>
> a* pa;
>
> };
>
> int main(void)
>
> {
>
> b b1;
>
> b1.pa->print( );
>
> }
>
>
>
>
>
>
>
>
>
>
>
> [Non-text portions of this message have been removed]
>
>  
>


[Non-text portions of this message have been removed]

Reply via email to