-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'的定義。 –