Entrepreneur
sınıfım için hem akış yerleştirme hem de çıkarma işlecini aşırı yüklemeye çalışıyorum. Benim main.cpp dosyasında Aşırı yükleme akışı ekleme ve çıkarma işleci
friend istream& Entrepreneur::operator>> (istream &input, Entrepreneur &entrepreneur) {
cout << "Please enter the item to be sold: ";
input >> entrepreneur.Item;
cout << "\nPlease enter the donation amount received: ";
input >> entrepreneur.Donation;
cout << "\nPlease enter the amount of members in the group: ";
input >> entrepreneur.Nr;
cout << "\nPlease enter the startup amount received: ";
input >> entrepreneur.StartupAmt;
cout << endl;
return input;
}
friend ostream& Entrepreneur::operator<< (ostream &output, Entrepreneur &entrepreneur) {
output << "Item: " << entrepreneur.Item << endl;
output << "Members in group: " << entrepreneur.Nr << endl;
output << "Startup amount: " << entrepreneur.StartupAmt << endl;
output << "Donation amount: " << entrepreneur.Donation << endl;
output << "Expenses: " << entrepreneur.Expenses << endl;
output << "Points earned: " << entrepreneur.Points << endl;
output << "All items sold: " << entrepreneur.Sold ? "Yes" : "No" << endl;
return output;
}
, ben aşağıdaki kodu çalışıyorum:
benim Girişimci sınıfında aşağıdaki var
int main() {
Entrepreneur Group3;
cin >> Group3;
}
kod derlenemiyor. Şu hata mesajını alıyorum:
siz yardım edebilir
İkili Operatörü '>>' türü 'istream' ve 'Girişimci' ifadesi için uygulanamaz Yukarıdaki kodda neyin yanlış olduğunu anlamaya mıyım?
Yardımın için teşekkürler. Bunu cevap olarak gönderebilir misiniz, böylece kabul edebilirim! –
Bu size bazı ek açıklamalar vermelidir: http://stackoverflow.com/questions/236801/should-operator-be-implemented-as-a-friend-or-as-a-member-function – Christophe