I am reading TCPPPL by Bjarne Stroustrup and I came across the following piece of code (shown below). I have two questions:
Where is the body of the function operator+? I mean there is only the declaration of the function in class X.
What does the line X(int) mean? Is this the constructor with int as a parameter or something else?
class X { public: void operator+(int); X(int); }; void operator+(X,X); void operator+(X,double); void f(X a) { a+1; // a.operator+(1) 1+a; // ::operator+(X(1),a) a+1.0; // ::operator+(a,1.0) }
operator+()or the constructor ofX, or the two versions ofoperator+()declared afterX. TheX(int)declares a constructor ofXthat accepts anintas argument. Unless the functions are defined (implemented) somewhere else, that code will compile, but linking will fail.