为对象函数创建一个线程给出了C2064

时间:2014-05-25 19:03:03

标签: c++ multithreading oop

我让这段代码通过了一个消息向量。我想要的是每个SESSION对象应该创建一个线程并在向量中搜索与其用户列表匹配的消息,在正向匹配上写入文件中的消息并从向量中删除该条目。这条线

process = std::thread{ &SESSION::sendMessage, this };

给了我

error C2064: term does not evaluate to a function taking 0 arguements. 

我无法弄清楚如何解决此错误。请帮忙 这是我的代码:

class SESSION
{
private:
    thread process;
    int static SessCount;
    const tm TimeofINIT;
    tm TimeofEND;
    const USER Creator;
    const USER Receiver;
    vector<Message> Conversation;
    string filename;
    static vector<something> UnsentMessages;
    friend void stripper(const string&);
    mutex locker;
    //void operator=(const SESSION&) = delete;
    //SESSION(const SESSION&) = delete;
public:
    SESSION(USER& starter, USER& recepient) : Creator(starter), Receiver(recepient), TimeofINIT(getTime()) {
        stringstream name, start;
        name << "SESSION" << SessCount << ".txt";
        filename = name.str();
        ofstream SessLog(filename, ios::out);
        start << "****SESSION INITIATED BETWEEN " << Creator.getName()
            << " AND " << Receiver.getName() << " AT: "
            << (showTime(TimeofINIT)).str() << "****" << endl;
        SessLog << start.rdbuf() << endl;
        SessCount++;
        process = std::thread{ &SESSION::sendMessage, this };
    }
    void operator=(const SESSION&){}
    SESSION(const SESSION& rv) : Creator(rv.Creator), Receiver(rv.Receiver), TimeofINIT(rv.TimeofINIT){}
    void sendMessage() {
        while (1) {
            for (unsigned int i = 0; i < UnsentMessages.size(); i++) {
                if (UnsentMessages[i].sender == Creator.getID() || UnsentMessages[i].sender == Receiver.getID() &&
                    UnsentMessages[i].reciever == Receiver.getID() || UnsentMessages[i].reciever == Creator.getID()) {
                    Writer(Receiver.getIP(), UnsentMessages[i].message);
                    storeMessage(Message(UnsentMessages[i].message));
                    UnsentMessages[i].read = true;
                    lock_guard<mutex> guard(locker);
                    deleteSentMsg(i);
                }
            }
        }
    }

0 个答案:

没有答案