编译器错误 - 在此上下文中是私有的 - 第 31 行

Compiler error - is private within this context - Line 31

#include<iostream>
#include<string>
using namespace std;

class Item{
    private:
        string type;
        string abbrv;
        string uID;
        int aircraft;
        double weight;
        string destination;
    public:
        void print(){
        cout << "ULD: " << type << endl;
        cout << "Abbreviation: " << abbrv << endl;
        cout << "ULD-ID: " << uID << endl;
        cout << "Aircraft: " << aircraft << endl;
        cout << "Weight: " << weight << " Kilograms" << endl;
        cout << "Destination: " << destination << endl;
   }

    friend void kilotopound(Item);
};
void kilotopound(Item I){
    cout << "Weight in Pounds: " << I.weight * 2.2 << " LBS " << endl;
}

int main(){
   Item I;
   I.type = "Container";
   I.uID = "AYK68943IB";
   I.abbrv = "AYK";
   I.aircraft = 737;
   I.weight = 1654;
   I.destination = "PDX";
   I.print();
   kilotopound(I);

   return 0;
}

从第 31 行开始我收到错误 'std::__cxxll::string Item::type' is private within this context

我主要是想通过这段代码将数据设为私有

class Item{
    public:
        string type;
        string abbrv;
        string uID;
        int aircraft;
        double weight;
        string destination;
    void print(){
        cout << "ULD: " << type << endl;
        cout << "Abbreviation: " << abbrv << endl;
        cout << "ULD-ID: " << uID << endl;
        cout << "Aircraft: " << aircraft << endl;
        cout << "Weight: " << weight << " Kilograms" << endl;
        cout << "Destination: " << destination << endl;
   }

    friend void kilotopound(Item);
};
void kilotopound(Item I){
    cout << "Weight in Pounds: " << I.weight * 2.2 << " LBS " << endl;
}

int main(){
   Item I;
   I.type = "Container";
   I.uID = "AYK68943IB";
   I.abbrv = "AYK";
   I.aircraft = 737;
   I.weight = 1654;
   I.destination = "PDX";
   I.print();
   kilotopound(I);

   return 0;
}

任何帮助将不胜感激,我只是对如何解决错误感到迷茫。谢谢!

此外,我还需要能够再次复制和输出复制的数据,如果有人可以提供帮助的话,还有私人数据。再次感谢!


#include<iostream>
#include<string>

using namespace std;

class Item{
    private:
        string type;
        string abbrv;
        string uID;
        int aircraft;
        double weight;
        string destination;
    public:
        Item(string t, string a, string u, int aC, double w, string d){
            type = t;
            abbrv = a;
            uID = u;
            aircraft = aC;
            weight = w;
            destination = d;
        }
        void print() {
          cout << "ULD: " << type << endl;
          cout << "Abbreviation: " << abbrv << endl;
          cout << "ULD-ID: " << uID << endl;
          cout << "Aircraft: " << aircraft << endl;
          cout << "Weight: " << weight << " Kilograms" << endl;
          cout << "Destination: " << destination << endl;
        }

    friend void kilotopound(Item);
};

void kilotopound(Item I){
    cout << "Weight in Pounds: " << I.weight * 2.2 << " LBS " << endl;
}

int main(){
   Item I ("Container", "AYK68943IB", "AYK", 737, 1654, "PDX");
   I.print();
   kilotopound(I);

   return 0;
}