473,655 Members | 3,105 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How use the overload of>> (or<<) of a class in the overload of << and >> of another class?

I have done the overload on the operator >> and << in the class Attore.
These 2 overload work correctly.
I have done the overload of the same overload in the class Film. The class
film ha inside an array of pointer to Attore.
I have written these overload in these ways. the overload of << work
correctly the overload of >> I don't know. I compile the class correctly,
when I insert a film through the operator >> I don't receive error, but when
I try to stamp the fil through the operator << I have an error during the
execution of program. Why this error? Depend from the overload of >>.
There are the overload of the operator<< and >>:
ostream & operator<<(ostr eam &out, const Film &f){
out<<f.getTitol o()<<endl;
out<<f.getAnno( )<<endl;
for(int i=0; i<f.countAttori (); i++){
out<<*(f.attori[i])<<endl; //use the overload of << in Attore, in Film I
have defined: Attore *attori[5]; this overload works correctly
}
return out;
}

istream & operator>>(istr eam &in, Film &f){
char nome[30];
int anno;
Attore a;
in>>nome;
in>>anno;
in>>a; //I use the overload of >> in Attore;
f.setTitolo(nom e);
f.setAnno(anno) ;
f.addAttore(a);
return in;
}

how can i resolve this problem?
Thanks

Jul 22 '05 #1
3 2235

"Piotre Ugrumov" <au************ @tin.it> wrote in message
news:1O******** *************@n ews4.tin.it...
I have done the overload on the operator >> and << in the class Attore.
These 2 overload work correctly.
I have done the overload of the same overload in the class Film. The class
film ha inside an array of pointer to Attore.
I have written these overload in these ways. the overload of << work
correctly the overload of >> I don't know. I compile the class correctly,
when I insert a film through the operator >> I don't receive error, but when I try to stamp the fil through the operator << I have an error during the
execution of program. Why this error? Depend from the overload of >>.
There are the overload of the operator<< and >>:
ostream & operator<<(ostr eam &out, const Film &f){
out<<f.getTitol o()<<endl;
out<<f.getAnno( )<<endl;
for(int i=0; i<f.countAttori (); i++){
problem with countAttori() perhaps?
out<<*(f.attori[i])<<endl; //use the overload of << in Attore, in Film I
have defined: Attore *attori[5]; this overload works correctly
}
return out;
}

istream & operator>>(istr eam &in, Film &f){
char nome[30];
int anno;
Attore a;
in>>nome;
This could overrun and will only get one word. Use a std::string.
in>>anno;
You are not checking for success at all.
in>>a; //I use the overload of >> in Attore;
You can have 5 actors but the input routine only allows 1.
f.setTitolo(nom e);
f.setAnno(anno) ;
f.addAttore(a);
does what to countAttori() ?
return in;
}

how can i resolve this problem?
Thanks

Jul 22 '05 #2
ostream & operator<<(ostr eam &out, const Film &f){
out<<f.getTitol o()<<endl;
out<<f.getAnno( )<<endl;
for(int i=0; i<f.countAttori (); i++){


problem with countAttori() perhaps?


countAttori() returns the number of Attore in the array. The max number is
5, but in the array could be less of 5.
I insert with the operator only 1 Attore.
In the overload of >> in the film I have written:
char title[30];
in>>title;
In this way I can give a title of only one word, with the use of string Can
I give a title with 2 or more word?
For insert a film I write this in the prompt:
Goffy(title) 1990(production year) Jacques(actor name) Rosseau(actor
surname) 11/11/1770(actor date of birth)
but hao can a give a title with 2 or more word?
Example:
Goffy go to disco(title) 1990(production year) Jacques(actor name)
Rosseau(actor surname) 11/11/1770(actor date of birth)
Thanks.

Jul 22 '05 #3

"Piotre Ugrumov" <au************ @tin.it> wrote in message
news:OD******** *************@n ews4.tin.it...
ostream & operator<<(ostr eam &out, const Film &f){
out<<f.getTitol o()<<endl;
out<<f.getAnno( )<<endl;
for(int i=0; i<f.countAttori (); i++){
problem with countAttori() perhaps?


countAttori() returns the number of Attore in the array. The max number is
5, but in the array could be less of 5.


I gathered that but where is the current size held and are you setting it on
?

I insert with the operator only 1 Attore.
In the overload of >> in the film I have written:
char title[30];
in>>title;
In this way I can give a title of only one word, with the use of string Can I give a title with 2 or more word?
No - the only simple way is to allow a whole line
for the title (and possibly every string field) and use getline to read it
(preferably into a std::string).
For insert a film I write this in the prompt:
Goffy(title) 1990(production year) Jacques(actor name) Rosseau(actor
surname) 11/11/1770(actor date of birth)
but hao can a give a title with 2 or more word?
Example:
Goffy go to disco(title) 1990(production year) Jacques(actor name)
Rosseau(actor surname) 11/11/1770(actor date of birth)
Thanks.

Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

77
5257
by: Gerrit Holl | last post by:
Hi, the <> inequality test operator has been deprecated for a loooooong time. Is there a reason that it doesn't trigger a DeprecationWarning? $ python2.2 -Wall -c "print 0 <> 0" 0 $ python2.3 -Wall -c "print 0 <> 0" False
14
5612
by: Dave | last post by:
Hello all, After perusing the Standard, I believe it is true to say that once you insert an element into a std::list<>, its location in memory never changes. This makes a std::list<> ideal for storing vertices of an arbitrary n-ary tree where a vertex contain pointers to its parent / children. These parent / child vertices need to stay put if we've got pointers to them somewhere! Am I correct in my assertion?
1
1928
by: Martin Schmid | last post by:
I'm getting a parser error message: Server tags cannot contain <% ... %> constructs... Ok.. so How do I accomplish this: For Each file in Files if ucase(right(file.name,7))<>ucase("_tn.jpg") and ucase(right(file.name,4))=ucase(".jpg") then tnName=left(file.name,len(file.name)-4) & "_tn.jpg"%> <asp:imagebutton runat="server" ImageUrl=<%=tnName%> onClick="IB_Click"/>
10
2617
by: dragoncoder | last post by:
Hi all, I am trying to understanding std::auto_ptr<Tclass implementation from "The C++ standard library" by Nicolai Josuttis. He gives a sample implementation of auto_ptr class template in section 4.2. The copy constructor is defined as: auto_ptr (auto_ptr& rhs) throw() : ap (rhs. release()) { }
22
3493
by: amygdala | last post by:
Hi, I'm trying to grasp OOP to build an interface using class objects that lets me access database tables easily. You have probably seen this before, or maybe even built it yourself at some point in time. I have studied some examples I found on the internet, and am now trying to build my own from scratch. I have made a default table class (DB_Table), a default validation class (Validator) which is an object inside DB_Table and my...
56
5144
by: Zytan | last post by:
Obviously you can't just use a simple for loop, since you may skip over elements. You could modify the loop counter each time an element is deleted. But, the loop ending condition must be checked on each iteration, since the Count changes as you delete elements. I would think it is guaranteed to be computed each time, and not cached. So, is this the best way?
6
4582
by: =?Utf-8?B?RmFiaWFu?= | last post by:
Hello, I have a class hierarchy distributed over 3 native C++ dlls. The base class has a .NET Windows.Form for status output via a gcroot<>. The gcroot is declared private - the sub classes only have access via a protected "print"-method. I need the different dlls as the sub classes implement the base class's pure virtual methods using different technologies. To use the native classes from outside their dlls I use the...
6
2818
by: Lasse Reichstein Nielsen | last post by:
Max <adsl@tiscali.itwrites: Not really. It shows that a particularly naïve implementation of a conversion from XML to JSON doesn't work well. What if the conversion of <e> some
2
4293
by: =?Utf-8?B?Unlhbg==?= | last post by:
Hi, How can I get around runtime error that says I can not explicit cast List<SubClassto ICollection<Class>? Generic List inhertis generic ICollection and Subclass inherits Class, then should not a problem to cast it explicitly, right?
0
8296
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8710
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8497
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8598
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7310
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1598
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.