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]> wrote: From: frankzhu_2001 <[EMAIL PROTECTED]> Subject: [c-prog] class composition To: [email protected] 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]
