mardi 29 mai 2018

Pass argument to member function as with std::cout

I want to create a class with a member function which can be used as std::cout. To demonstrate the problem I created this code example

#include <iostream>
#include <string>

class myClass
{
public:
    void myFunc(? data)
    {
        std::cout << data << std::endl;
    }
};

int main()
{
    myClass myObject;
    int var = 1;
    myObject.myFunc() << "Text" << var;
}

As you can see I would like to pass arguments to the function as if I would have used std::cout directly. Is that possible? I searched the net and read a lot but didn't get it to work, can anybody help or link a page with more information? Thank you very much.

Aucun commentaire:

Enregistrer un commentaire