friend vli &vli::operator + (int &a,vli &obj);
Since operator+ is defined as a friend it will not be a member of vli.
And also, you cannot return a reference to vli
#include <iostream>
struct Int {
Int() { }
explicit Int( int num ) : n_(num) { }
Int& operator= ( const Int& num ) { n_ = num.n_; return *this; }
int get() const { return n_; } // no need to make operator+ friend if u have accessor
private :
friend Int operator+ ( int lhs, const Int& rhs ); // cannot return a reference to Int
int n_;
};
// ~~ CPP :
Int operator+ ( int lhs, const Int& rhs ) // cannot return a reference to Int
{ return Int( lhs + rhs.n_ ); }
int main()
{
Int i( 100 );
Int j;
j = 123 + i;
std::cout << j.get(); // 223
}