#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!
CodePudding user response:
#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;
}