For example: # Include <iostream> <br/> using namespace STD; <br/> class cylinder <br/> {<br/> friend istream & operator> (istream & is, cylinder & CY); <br/> Public: <br/> inline double square () <br/> {return length * (width + height) * 2 + width * height * 2;} <br/> inline double volume () <br/> {return length * width * height;} <br/> PRIVATE: <br/> double length; <br/> double width; <br/> double height; <br/> }; <br/> istream & operator> (istream & is, cylinder & CY) <br/>{< br/> cout <"input length:" <Endl; <br/> is> cy. length; <br/> cout <"input width:" <Endl; <br/> is> cy. width; <br/> cout <"input Height:" <Endl; <br/> is> cy. height; <br/> return is; <br/>}< br/> int main () <br/>{< br/> cylinder first; <br/> CIN> first; <br/> cout <first. square () <Endl; <br/> cout <first. volume () <Endl; <br/> return 0; <br/>}< br/> These Code Cannot be compiled and passed in vc6.0: The system prompts that the private member cannot be accessed and the access permission is not available. The Code is as follows: # Include <iostream> <br/> Using STD: CIN; <br/> Using STD: Endl; Using STD: cout; <br/> Using STD :: ostream; <br/> Using STD: istream; <br/> Using STD: ostream; <br/> class cylinder <br/> {<br/> friend istream & operator> (istream & is, cylinder & CY); <br/> public: <br/> inline double square () <br/> {return length * (width + height) * 2 + width * height * 2 ;} <br/> inline double volume () <br/> {return length * width * height;} <br/> PRIVATE: <br/> double length; <br/> double width; <br/> double height; <br/>}; <br/> istream & operator> (istream & is, cylinder & CY) <br/>{< br/> cout <"input length:" <Endl; <br/> is> cy. length; <br/> cout <"input width:" <Endl; <br/> is> cy. width; <br/> cout <"input Height:" <Endl; <br/> is> cy. height; <br/> return is; <br/>}< br/> int main () <br/>{< br/> cylinder first; <br/> CIN> first; <br/> cout <first. square () <Endl; <br/> cout <first. volume () <Endl; <br/> return 0; <br/>}</P> <p> Cause: This is said to be a classic bug of VC. And namespace. If using namespace STD is contained, a prompt is displayed, indicating that the member function has no permission to access the private member. Solution: Remove using namespace STD and replace it with a smaller namespace. For example: Adding Using STD: string to # include <string> Adding Using STD: fstream to # include <fstream> To include # include <iostream>, you must add Using STD: CIN; Using STD: cout; Using STD: ostream; Using STD: istream; Using STD: Endl;, etc, what is needed. |