Problem Implementing OSTREAM :(

Hi there, I badly need suggestions. Please take a look at this.

Implementation:
 
 friend std::ostream& operator<<(std::ostream&, const Students&);


and it comes with this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
std::ostream& operator<<(std::ostream& ostr,const Students& dl)
{
	if(dl.empty())ostr<<" The list is empty "<<endl;
	else {
		Students::nodeS* curr;
		for(curr=dl.head;curr!=dl.last->next;curr=curr->next)
		ostr<<curr->dataS.Sname<<" ";
		ostr<<curr->dataS.idno<<" ";
		ostr<<curr->dataS.year<<" ";
		ostr<<curr->dataS.bb<<" ";
		ostr<<endl;
		ostr<<endl;
		return ostr;
	}
}


but then, it would give me an error stating that:

1
2
Warning	1	
warning C4715: 'operator<<' : not all control paths return a value


I don'tknow what to do,I can't display the student's list because of this. Please help. :(
Thank you :D every reply is very well appreciated :D
Change this statement

if(dl.empty())ostr<<" The list is empty "<<endl;

to

if ( dl.empty() ) return ostr<<" The list is empty "<<endl;
I'd remove the return ostr from the else and place it before the last closing brace.
1
2
3
4
5
...
    ostr << endl;
    }
    return ostr;
}
Last edited on
Thank you Mr. Vlad and Mr. Jlb, I will follow both of your suggestions :)
Topic archived. No new replies allowed.