Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct mint {
- private:
- int val;
- static int const mod = 7;
- public:
- mint(int x) : val(x) {
- cout << "Int constructor called with " << x << '\n';
- }
- mint() {val = 0;}
- mint(mint &other) {
- val = other.val;
- cout << "Copy constructor called " << val << '\n';
- }
- // 13 + ins means 13 ko construct krega mint me and then call this
- friend mint operator+(mint a, mint const b) {
- a.val += b.val;
- cout << "+ operator called " << b.val << '\n';
- return a;
- }
- // https://softwareengineering.stackexchange.com/a/68888
- friend mint operator+(int x, mint other) {
- mint tmp(x);
- tmp.val += other.val;
- cout << "+ operator called " << other.val << '\n';
- return tmp;
- }
- };
- // or
- // mint operator+(int x, mint other) {
- // mint tmp(x);
- // tmp.val += other.val;
- // cout << "+ operator called " << other.val << '\n';
- // return tmp;
- // }
- int main() {
- mint ins(10);
- ins = 23 - 13 + ins + 13;
- return 0;
- }#include <bits/stdc++.h>
- using namespace std;
- struct mint {
- private:
- int val;
- static int const mod = 7;
- public:
- mint(int x) : val(x) {
- cout << "Int constructor called with " << x << '\n';
- }
- mint() {val = 0;}
- mint(mint &other) {
- val = other.val;
- cout << "Copy constructor called " << val << '\n';
- }
- // 13 + ins means 13 ko construct krega mint me and then call this
- friend mint operator+(mint a, mint const b) {
- a.val += b.val;
- cout << "+ operator called " << b.val << '\n';
- return a;
- }
- // https://softwareengineering.stackexchange.com/a/68888
- friend mint operator+(int x, mint other) {
- mint tmp(x);
- tmp.val += other.val;
- cout << "+ operator called " << other.val << '\n';
- return tmp;
- }
- };
- // or
- // mint operator+(int x, mint other) {
- // mint tmp(x);
- // tmp.val += other.val;
- // cout << "+ operator called " << other.val << '\n';
- // return tmp;
- // }
- int main() {
- mint ins(10);
- ins = 23 - 13 + ins + 13;
- return 0;
- }#include <bits/stdc++.h>
- using namespace std;
- struct mint {
- private:
- int val;
- static int const mod = 7;
- public:
- mint(int x) : val(x) {
- cout << "Int constructor called with " << x << '\n';
- }
- mint() {val = 0;}
- mint(mint &other) {
- val = other.val;
- cout << "Copy constructor called " << val << '\n';
- }
- // 13 + ins means 13 ko construct krega mint me and then call this
- friend mint operator+(mint a, mint const b) {
- a.val += b.val;
- cout << "+ operator called " << b.val << '\n';
- return a;
- }
- // https://softwareengineering.stackexchange.com/a/68888
- friend mint operator+(int x, mint other) {
- mint tmp(x);
- tmp.val += other.val;
- cout << "+ operator called " << other.val << '\n';
- return tmp;
- }
- };
- // or
- // mint operator+(int x, mint other) {
- // mint tmp(x);
- // tmp.val += other.val;
- // cout << "+ operator called " << other.val << '\n';
- // return tmp;
- // }
- int main() {
- mint ins(10);
- ins = 23 - 13 + ins + 13;
- return 0;
- }
Add Comment
Please, Sign In to add comment