Jump to content

Eugine Savin

Members
  • Content Count

    7
  • Joined

  • Last visited

Community Reputation

1 Neutral
  1. Eugine Savin

    operator overloding Equal vs Multiply

    In C++ there is not differences between functions and overloaded operators. struct MyArray { public: template <std::size_t N> bool operator==(int (&rhs)[N]) { std::cout << N << '\n'; return true; } }; int main() { // your code goes here int arr1 [1] = {0}; int arr2 [2] = {0, 0}; MyArray myArr; if (myArr == arr1 && myArr == arr2) {} return 0; } Can you explain why you allow operators with dyn arrays, and do not allow ones with open arrays ?
  2. Eugine Savin

    operator overloding Equal vs Multiply

    TMyArray = record .. end; const Arr1: array[0..1] of Integer = (..) const Arr2: array[0..2] of Integer = (..) var MyArray: TMyArray .. I wanna have ability to compare if (MyArray == Arr1) or (MyArray = Arr2).. How can I get it without open arrays as operator parameters ?
  3. Eugine Savin

    operator overloding Equal vs Multiply

    What's problems with open arrays ? Anyway if I replace "array of Integer" by "TArray<Double>" r * [10.0] - compiled, but r = [10.0] is not ( E2001 Ordinal type required) // qc link https://quality.embarcadero.com/browse/RSP-23498
  4. Eugine Savin

    operator overloding Equal vs Multiply

    And main question, why r := r * [10] // here [10] is array and b := r = [10] // here [10] is set what's difference ??
  5. Eugine Savin

    operator overloding Equal vs Multiply

    Well, where is not "set of Integer", but code var i: Integer; begin i := 10; b := r = [i]; end is not compiled
  6. Simple question, why "Multiply" operator works, and "Equal" does not. compiler give error "[dcc32 Error] Project1.dpr(33): E2015 Operator not applicable to this operand type" program Project1; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; type TMyRecord2 = record public class operator Equal(const a: TMyRecord2; const b: array of Integer): boolean; class operator Multiply(const a: TMyRecord2; const b: array of Integer): TMyRecord2; end; class operator TMyRecord2.Equal(const a: TMyRecord2; const b: array of Integer): boolean; begin Result := True; end; class operator TMyRecord2.Multiply(const a: TMyRecord2; const b: array of Integer): TMyRecord2; begin Result := a; end; var b: boolean; r: TMyRecord2; begin try r := r * [10]; // this line is compiled b := r = [10]; // this line is not compiled except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end.
×