Saturday, February 12, 2022

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

An overloaded unary operator may return any type. The following example overloads the ! operator:


#include <iostream>

using namespace std;


struct X { };


void operator!(X) {

  cout << "void operator!(X)" << endl;

}


struct Y {

  void operator!() {

    cout << "void Y::operator!()" << endl;

  }

};


struct Z { };


int main() {

  X ox; Y oy; Z oz;

  !ox;

  !oy;

//  !oz;

}

  !oy;

//  !oz;

}

No comments:

Post a Comment

n8n index

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