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 239 views
1 answer 173 views
1 answer 187 views
1 answer 215 views
215 views asked Mar 28, 2019 by avibootz
1 answer 145 views
145 views asked Mar 24, 2018 by avibootz
1 answer 211 views
...