Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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!

>Solution :


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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading