Home:ALL Converter>Compiler error - is private within this context - Line 31

Compiler error - is private within this context - Line 31

Ask Time:2022-02-13T12:31:13         Author:Jim Crawford

Json Formatter

#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;
}

Starting on line 31 I'm getting the error 'std::__cxxll::string Item::type' is private within this context

I'm basically trying to make the data private from this code

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;
}

Any help would be greatly appreciated, I'm just sort of lost on how I can resolve the error. Thanks!

Also I need to be able to copy and output the copied data once again if anyone can help with that as well, with private data too. Thanks again!

Author:Jim Crawford,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/71097924/compiler-error-is-private-within-this-context-line-31
yy