#include "stdafx.h"
#include "iostream"
#include "string"
#include <set>
#include <algorithm>
using namespace std;
class student {
public:
bool operator< (student &ob2) {
return true;
}
student() {
a = 0;
fio = "Kolesnikov Vadim Sergeevich";
vuz = "PSU";
fac = "Facultet";
kaf = "Kafedra";
f_o = "Ochka\Zaochka";
}
student(char *fio1, int a1) {
a = a1;
fio = fio1;
vuz = "VUZ";
fac = "Facultet";
kaf = "Kafedra";
f_o = "Ochka\Zaochka";
}
~student() {};
void output() {
cout << fio.c_str() << endl;
cout << vuz.c_str() << endl;
cout << fac.c_str() << endl;
cout << kaf.c_str() << endl;
cout << f_o.c_str() << endl << endl;
}
void input() {
cout << "FIO:";
cin >> fio;
cout << "vuz:";
cin >> vuz;
cout << "fac:";
cin >> fac;
cout << "kaf:";
cin >> kaf;
cout << "f_o:";
cin >> f_o;
cout << endl;
}
protected:
string kaf;
string f_o;
int a;
private:
string fio;
string vuz;
string fac;
};
void main(void)
{
char str0[] = "Potogin Nikita";
char str1[] = "Sidelnikov Maxim";
char str2[] = "Kolesnikov Vadim";
char str3[] = "Fedoseev Gena";
student ob0(str0,1);
student ob1(str1,2);
student ob2(str2,3);
student ob3(str3,4);
ob0.output();
multiset<student> list;
multiset<student>::iterator it;
list.insert(ob0);
list.insert(ob1);
list.insert(ob2);
list.insert(ob3);
system("pause");
}
Необходимости засовывать оператор в класс не было. Наоборот, правильнее перегружать такой оператор отдельной функцией.
В любом случае, оба параметра оператора сравнения должны быть константными
bool operator< (const student &ob2) const {
return true;
}
Оператор сравнения, который всегда return true; - грубое нарушение требований, накладываемых на оператор сравнения. Работать не будет.
Что такое
#include "iostream"
#include "string"
? При включении стандартных заголовков, скобки должны быть только треугольными.
int main, а не void main.
operator< должен принимать константные ссылки
bool operator< (const student &ob1, const student &ob2)
И, само собой, он не должен быть тривиальным.
f_o = "Ochka\\Zaochka";
Бекслеши в строковых константах надо удваивать
int main(void)
main () надо декларировать с int, а не void и возвращать 0.
нужны константные ссылки
bool operator< (const student &ob1, const student &ob2) {
return true;
}
или использовать lamda:
int main(void)
{
char str0[] = "Potogin Nikita";
char str1[] = "Sidelnikov Maxim";
char str2[] = "Kolesnikov Vadim";
char str3[] = "Fedoseev Gena";
student ob0(str0,1);
student ob1(str1,2);
student ob2(str2,3);
student ob3(str3,4);
ob0.output();
// вместо просто возврата true, наверное должно возвращаться что-то осмысленное
auto comp = [](const student& lst, const student& rst){ return true; };
typedef multiset<student, decltype(comp)> myset;
myset list(comp);
myset::iterator it;
list.insert(ob0);
list.insert(ob1);
list.insert(ob2);
list.insert(ob3);
system("pause");
}
Сборка персонального компьютера от Artline: умный выбор для современных пользователей