0

I made this code to go through a vector of messages. What i wanted was that each SESSION object should create a thread and search the vector for messages which matched its user list and on a positive match write the message in a file and delete the entry from the vector. the line

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

gives me

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

I cannot figure out how to resolve this error. Please help This is my code:

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);
                }
            }
        }
    }
πάντα ῥεῖ
  • 85,314
  • 13
  • 111
  • 183
  • Just throwing your code here asking us to debug it, isn't very productive! – πάντα ῥεῖ May 25 '14 at 19:08
  • I'm sorry. This is my first time asking a question on stackoverflow. I made this code to go through a vector of messages. What i wanted was that each SESSION object should create a thread and search the vector for messages which matched its user list and on a positive match write the message in a file and delete the entry from the vector. the line 'process = std::thread{ &SESSION::sendMessage, this };' gives me error C2064: term does not evaluate to a function taking 0 arguements – user3674302 May 25 '14 at 19:12
  • Please edit your question, to improve it with additional information. You might also want to [**read this**](http://stackoverflow.com/help/on-topic) before asking a question here. – πάντα ῥεῖ May 25 '14 at 19:14
  • possible duplicate of [Start thread with member function](http://stackoverflow.com/questions/10673585/start-thread-with-member-function) – aruisdante May 25 '14 at 19:24
  • Why are you passing this as a parameter to sendMessage which has none? – o_weisman May 25 '14 at 19:30
  • I did try it without 'this' too. It didn't work. – user3674302 May 25 '14 at 19:37
  • Your code compiles without all mumbo-jambo in constructor. Thread creation line seems correct. This is how you assign member function to a thread. Can you provide a compilable code where it produces said error? – Cengiz Kandemir May 25 '14 at 20:10
  • I agree with @CengizKandemir. Please post a [mcve](http://stackoverflow.com/help/mcve). The line seems ok to me. – eerorika May 25 '14 at 20:16

0 Answers0