Just wondering which of these functions would be faster (or if they would be the same):

class MyClass
{
    private:
    bool MyVar;
    public:
    MyClass &Function1(bool MyVar);
    MyClass &Function2(bool MyVar);
    MyClass &Function3(bool var);
};
MyClass &MyClass::Function1(bool MyVar)
{
    this->MyVar=MyVar;
    cout<<MyVar;
    return *this;
}
MyClass &MyClass::Function2(bool MyVar)
{
    this->MyVar=MyVar;
    cout<<this->MyVar;
    return *this;
}
MyClass &MyClass::Function3(bool var)
{
    MyVar=var;
    cout<<MyVar;
    return *this;
}

Recommended Answers

All 2 Replies

Your question is: does prefixing this to member access have a performance cost? The answer is no, it should not.

Thanks that answers it!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.