C++ 重载的提取运算符无法访问成员变量
我有以下头文件:C++ 重载的提取运算符无法访问成员变量,c++,encapsulation,C++,Encapsulation,我有以下头文件: #include <iostream> #include "product.h" using namespace std; class ProductInfo : Product { int UPC; public: ProductInfo() : Product(NULL, 0.0), UPC(0) friend istream& operator>>(istream& is, ProductInfo& pin
#include <iostream>
#include "product.h"
using namespace std;
class ProductInfo : Product
{
int UPC;
public:
ProductInfo() : Product(NULL, 0.0), UPC(0)
friend istream& operator>>(istream& is, ProductInfo& pinfo);
};
我是否做错了什么,或者这是我的IDE的问题?类ProductInfo:Product表示私有继承;因此,
ProductInfo
(及其好友)无法通过名称访问Product
的私有或受保护成员
可能您想使用公共继承:
class ProductInfo : public Product
它说,
Product::price是不可访问的
,请注意。您只是将输出操作符与ProductInfo
作为好友,而不是与继承的private
作为好友。请发布Product
的定义。
class ProductInfo : public Product