error C2593: 'operator <<' is ambiguous
i have some problems with template operator<< having a code:
class Manager
{
multiset<Advertising*, CompareAddPtr > AddToSend;
LinkedList<Client > ClientList;
LinkedList<Client > ActiveClientList;
list<string> initList;
list<string> commandsList;
}
in this class i try to use this method:
void Manager:: PrintAllClientDetialsTofile()
{
ofstream myfile;
myfile.open ("Result.txt",开发者_开发问答ios::app);
myfile << ClientList;
myfile << "\n";
myfile.close();
}
my << function in the template class:
template <class L> ostream & operator<<(ostream& os,const LinkedList<L>& listToprint)
{
Link<T> * tmp = listToprint->pm_head;
for(int i=0;i<listToprint.GetNumOfElements();i++)
{
os<<*(tmp->m_data);
tmp=tmp->m_next;
}
return os;
}
i also have template class
template <class T> class Link {
private:
T* m_data;
Link* m_next;
Link* m_prev;
the client class:
#pragma once
#ifndef _CLIENT_H_
#define _CLIENT_H_
#include <string>
#include <set>
#include "Advertising.h"
#include "Email.h"
#include "FaceBook.h"
#include "Msn.h"
#include "Sms.h"
#include "Bill.h"
#include <ostream>
#include "LinkedList.h"
using namespace std;
struct CompareAddPtrClient : public std::binary_function<Advertising*, Advertising*, bool>
{
bool operator()(Advertising* x, Advertising* y) const
{
if(x->GetMadeOrderTime()<y->GetMadeOrderTime())
return true;
else
return false;
}
};
class Client
{
string m_clientname;
string m_companyName;
string m_cod;//check if have length of 15
string m_telephone;
string m_email;
int m_lastOrder;
int m_orderUntill;
multiset<Advertising*, CompareAddPtrClient > m_clientsAdds;
LinkedList<Bill > BillsForClient;
public:
Client(string clientName,string companyName,string cod,string telephone,string email);
Client(string clientName);
~Client(void);
//getters
LinkedList<Bill >* GetClientsBills(){return &BillsForClient;}
const string GetTelephoneNum()const {return m_telephone;}
const string GetEmail()const{return m_email;}
const int GetClientUntill()const{return m_orderUntill;}
const int GetLastOrderTime()const{return m_lastOrder;}
//setters
void UpdateLastTimeMadeOrder(int theday){m_lastOrder=theday;}
void UpdateOrderUntill(int theday){m_orderUntill=theday+7;}
//functions
friend ostream & operator<<(ostream& os,const Client& print);
bool operator==(const Client & other)const;
void PrintOrdersForClient()const;
void AddAdvertuseForClient(Advertising * add);
void LastOrdersByClient();
void PrintClientsBills();
};
#endif
when i use this function to print my list i get compile error:
error C2593: 'operator <<' is ambiguous
i found similar question that was asked the question but i don't understand how to solve this problem.
thank you :)
"operator <<
is ambiguous" is an error that occurs because the compiler has found 2 (or more) << operators that your input types (the output stream and the linked list in this case) apply to. The compiler has two functions, either of which are valid to call, and it doesn't know which it should pick.
Your posted code, however, doesn't show us enough to tell you more than that, and by itself, doesn't seem to have anything that would cause this message. (This error usually comes from multiple pieces of code acting against each other, not from any one spot in the code.) Usually, that error message is followed by the compiler telling you which two operator <
精彩评论