-2
我有以下的头文件:重载提取操作无法访问成员变量
#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);
};
Product
包含一个受保护的变量float price
当我尝试我的提取操作中更改float price
,我的IDE(克利翁)告诉我protected 'Product::price is inaccessible'
这里是一个cpp文件中的相关代码:
#include "productinfo.h"
istream& operator>>(istream& is, ProductInfo& pinfo)
{
char info[256];
if (is.getline(info, 256))
{
strtok(info, ",");
pinfo.UPC = atoi(info);
pinfo.setName(strtok(NULL, ","));
pinfo.price = atof(strtok(NULL, ","));
}
return is;
}
我做错了什么,或者这是我的IDE的问题?
它说,'产品::价格inaccessible',你要小心。 –
你只是用'ProductInfo'输出运算符,而不是''继承'private'。 –
请寄出'Product'的定义。 –