Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 26.12.2011, 16:48   #1
vbnmrf
 
Регистрация: 15.11.2011
Сообщений: 8
По умолчанию Проблемы с перегрузкой

Проблема в следующем: для вывода очереди пытаюсь перегрузить оператор вывода <<, код:
#include <iostream>
#include <fstream>
#include <string.h>
#include <iomanip>
#include <stdio.h>
using namespace std;
class queue
{
private:
struct ch
{
ch* next;
int data;
};
ch* first;
ch*last;
public:
bool inqueue(int a)
{
ch* tp=first;
while (tp)
{
if (tp->data==a)
return true;
tp=tp->next;
}
return false;
}
bool isempty()
{
return(!first);
}
queue()
{
last=first=0;
}
~queue()
{
ch*tp;
while (first)
{
first=first->next;
delete tp;
tp=first;
}
}
int add(int a)
{
ch*tp=new ch;
tp->data=a;
tp->next=NULL;
if(!isempty())
{
last->next=tp;
last=tp;
}
else
{first=last=tp;}
return 0;
}
int del()
{
if(!isempty())
{
int a=first->data;
ch*tp=first;
first=first->next;
delete tp;
}
else
{
cout<<"O4ered' pusta!\n";
system("pause");
exit(0);
}
return 0;
}
const ostream& operator<<(ostream &s,const queue q)
{
if (q.first)
{
ch*tp = q.first;
while (tp)
{
s<<tp->data <<" ";
tp=tp->next;
}
}
return s;
}
};
bool prosto(int a)
{
if (a < 2)
return false;
if (a==2)
return true;
for (int i = 2; i <= a/2; i++)
if (!(a%i))
return false;
return true;
}
bool palindrom(int a)
{
int b=0, c=a;
while (a)
{
b=b*10+a%10;
a=a/10;
}
if (b==c)
return true;
else
return false;
}
int vvod(queue &q1, queue &q2)
{
ifstream fin("input.txt");
if (fin.good())
{
while (!fin.eof())
{
int a;
fin>>a;
if (prosto(a))
q1.add(a);
if (palindrom(a))
q2.add(a);
}
}
fin.close();
return 0;
}
int queue3(queue q1,queue q2,queue &q3)
{
while (!q1.isempty())
{
int a=q1.del();
if (!q3.inqueue(a))
q3.add(a);
}
while(!q2.isempty())
{
int a=q2.del();
if (!q3.inqueue(a))
q3.add(a);
}
return 0;
}
int vivod(string name,queue q)
{
cout<<"\nrezalt:\n"<<q;
ofstream fout(name);
if (fout.is_open())
{
fout<<q;
cout<< "\nAll Ok.\n";
}
fout.close();
return 0;
}
int main()
{
queue q1;
queue q2;
vvod(q1,q2);
cout<<"Prostie:\n"<<q1;
cout<<"Palindromi:\n"<<q2;
queue q3;
queue3(q1,q2,q3);
vivod("text.txt",q3);
system("pause");
return 0;
}



Но компилятор выдает ошибку: const std:stream& queue:: operator<<(std:stream&,queue) must take exactly only one argument...
Тоесть данная перегрузка должна якобы содержать 1 аргумент...
пробовал писать const queue q в самой в функции, тогда перегрузка не работает... Подскажите плз в чем ошибка?
vbnmrf вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
проблема с перегрузкой оператора потока в классах - << monolit111 Общие вопросы C/C++ 13 27.11.2011 20:40
Проблемы с перегрузкой в с++ Lazy maximka Помощь студентам 9 30.10.2011 20:12
Проблема с перегрузкой операторов в C++ StudentofSUSU Помощь студентам 2 30.09.2010 10:04
Проблема с перегрузкой операторов, не могу разобраться mrLee Помощь студентам 1 30.01.2010 00:23
Проблема с перегрузкой операторов, не могу разобраться mrLee Общие вопросы C/C++ 0 29.01.2010 18:45