M
M
Mikhal24062014-02-25 14:38:33
C++ / C#
Mikhal2406, 2014-02-25 14:38:33

Working with STL Problem with passing objects by reference

/*I can't understand why the compiler allows
passing references to some of its predicates. And some don't. The transform algorithm also does not work (it produces binary '=' : no operator found which takes a left-hand operand of type 'const Driver' (or there is no acceptable conversion)). I drop the header file here where the Driver class is declared. And the main cpp. I would be very grateful for constructive criticism and help.*/
//Driver.h
#pragma once;
#include
#include
using namespace std;
class Driver
{
private:
int number_of_journey;
stringname;
int number_of_auto;
string mark_of_auto;
public:
Driver()
{ }
Driver(int n,string s,int n1,string s1)
{
number_of_journey=n;
name=s;
number_of_auto=n1;
mark_of_auto=s1;
}
Driver(const Driver& a)
{
number_of_journey=a.number_of_journey;
name=a.name;
number_of_auto=a.number_of_auto;
mark_of_auto=a.mark_of_auto;
}
~Driver()
{ }
friend ostream& operator<<(ostream& s,const Driver& a)
{
s<>(istream& s,Driver& a)
{
s>>a.number_of_journey;
s>>a.name;
s>>a.number_of_auto;
s>>a.mark_of_auto;
return s;
{
return number_of_auto;
}
int number_of_travelling()
{
return number_of_journey;
}
Driver& operator =(const Driver& a)
{
number_of_journey=a.number_of_journey;
name=a.name;
number_of_auto=a.number_of_auto;
mark_of_auto=a.mark_of_auto;
return *this;
}
string& get_name()
{
return name;
}
string& mark_auto()
{
return mark_of_auto;
}
};
//main.cpp
#include "Driver.h"
#include
#include
#include
#include
#include
#include
#include
#include
bool auto_predicate(Driver& a,Driver& b)
{
return a.number_of_autobus()>b.number_of_autobus();
}
bool travelling_predicate(Driver& a,Driver& b)
{
return a.number_of_travelling()>b.number_of_travelling();
}
void show_number_of_travel(Driver a)
{
cout<b.get_name();
}
};
int main()
{
ifstream file;
file.open("Drivers_info.txt");
vectormyvector;
istream_iterator istiter(file);
istream_iterator end_of_file;
copy(istiter,end_of_file,back_inserter(myvector));
deque mydeque(myvector.begin(),myvector.end());
list mylist(myvector.begin(),myvector.end());
cout<<"Sorting according to the number of auto"< ostiter(cout,"\n");
copy(mylist.begin(),mylist.end(),ostiter);
cout<<"Sorting according to the travelling number"<(cout,"\n"));
set myset(mydeque.begin(),mydeque.end());
cout<<"Number of travel lists"<::iterator iter;
iter=myset.find(Mick);
if(iter!=myset.end())
{
myset.erase(iter);
cout<<"Set after removal of Mick"< new_set;
transform(myset.begin(),myset.end(),myset.begin(),bind2nd(ptr_fun(modify_name),"King"));
return 0;

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question