错误 C2593:'运算符 <<'含糊不清
我对模板运算符有一些问题<< 有一个代码:
class Manager
{
multiset<Advertising*, CompareAddPtr > AddToSend;
LinkedList<Client > ClientList;
LinkedList<Client > ActiveClientList;
list<string> initList;
list<string> commandsList;
}
在这个类中我尝试使用这个方法:
void Manager:: PrintAllClientDetialsTofile()
{
ofstream myfile;
myfile.open ("Result.txt",ios::app);
myfile << ClientList;
myfile << "\n";
myfile.close();
}
我的<<模板类中的函数:
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;
}
我还有模板类
template <class T> class Link {
private:
T* m_data;
Link* m_next;
Link* m_prev;
客户端类:
#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
当我使用此函数打印我的列表时,我收到编译错误:
错误 C2593:“运算符 <<”是 模棱两可
我发现有人问过类似的问题 问题 但我不明白如何解决这个问题。
谢谢 :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“
operator <<
is ambigacy”是由于编译器发现 2 个(或更多)<< 操作符而发生的错误。您的输入类型(本例中为输出流和链表)适用的运算符。编译器有两个函数,其中任何一个都可以有效调用,但它不知道应该选择哪个。然而,您发布的代码并没有向我们展示足够多的信息来告诉您更多信息,并且其本身似乎没有任何内容会导致此消息。 (此错误通常来自多段相互影响的代码,而不是来自代码中的任何一个位置。)通常,该错误消息后面跟着编译器,告诉您哪两个运算符 < > 。
"
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 <