Can a class function return an instance of itself. And how to implement it, i.e. eg

function vector.rot(a:single=0):vector; begin a:=a*pi/180; rot:=vector.create(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); end; 

How to make it so that a new instance of the class is not created with changed parameters relative to the base (input), but instead the parameters of the input instance would change (I know the parameters to change) and it would return as a function.

  • 2
    I did not understand chewing. Return Self ? In my opinion, it's time to read something about the PLO and many questions will disappear by themselves. - karmadro4
  • so in one book it is not written about implementations in delphi / free pascal. in at least two books, there are chapters of the "fundamentals of the PLO", but there self is not mentioned even as for the overload of the destroyer. - Pavel
  • Obviously, if in the book "forgot" to mention Self , then this book should be in the stove and take another :-) Unfortunately, I can not advise anything, I studied OOP for a very long time. - karmadro4

1 answer 1

 function vector.rot(a:single=0):vector; var x1,y1: Integer; begin a:=a*pi/180; x1:=x*cos(a)-y*sin(a); y1:=x*sin(a)+y*cos(a); x:=x1; y:=y1; rot:=Self; end;