Sunday, February 13, 2022

[c++] Overloading binary operators (C++ only)

 #include <iostream>

using namespace std;

struct X {

  // member binary operator

  void operator*(int) { 

    cout << "void operator*(int)" << endl;

  }

};

// non-member binary operator

void operator*(X, float) { 

    cout << "void operator*(X, float)" << endl;

}

int main() {

  X x;

  int y = 10;

  float z = 10;


  x * y;

  x * z;

}



void operator*(int)

void operator*(X, float)

No comments:

Post a Comment

n8n index

 【n8n免費本地端部署】Windows版|程式安裝x指令大補帖  【一鍵安裝 n8n】圖文教學,獲得無限額度自動化工具&限時免費升級企業版功能