错误C2593:'运算符<<'模棱两可 [英] error C2593: 'operator <<' is ambiguous

查看:79
本文介绍了错误C2593:'运算符<<'模棱两可的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在模板运算符上有一些问题<< 有验证码:

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;
 }

我也有模板类

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

当我使用此功能打印列表时,出现编译错误:

when i use this function to print my list i get compile error:

错误C2593:操作员<<"是

error C2593: 'operator <<' is ambiguous

我发现了类似的问题 问题 但是我不知道如何解决这个问题.

i found similar question that was asked the question but i don't understand how to solve this problem.

谢谢:)

推荐答案

"operator <<不明确"是由于编译器发现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.

这篇关于错误C2593:'运算符&lt;&lt;'模棱两可的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆