In vc6_0, The youyuan function cannot resolve private members of the class-classic bug in vc6_0)

Source: Internet
Author: User

Conversion from http://hi.baidu.com/zgjxwl/blog/item/f0382a6e4ea08ddc80cb4a3d.html)

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.