How to define friend function in class with C++

1 Answer

0 votes
#include <iostream>

class Test {  
 int x = 3, y = 4;;  
 
 public:  
    friend int mul(Test t) {  
        return(t.x * t.y);  
    }  
};  

int main() {  
    Test t;  
    int result = mul(t);  
    
    std::cout << result;  
    
    return 0;  
}  



/*
run:

12

*/

 



answered Oct 6, 2019 by avibootz

Related questions

1 answer 217 views
1 answer 157 views
1 answer 170 views
1 answer 198 views
198 views asked Mar 28, 2019 by avibootz
1 answer 131 views
131 views asked Mar 24, 2018 by avibootz
1 answer 188 views
...