I have a class with 3 fields a,b and c. I want to calculate the volume of a box with sides a,b or c. I want to do this with a friend function. However, when I compile the program the Compiler gives an error No global operator found which takes type Box. I would like to ask why is that?
#include "pch.h"
#include <iostream>
using namespace std;
class Box {
double a, b, c;
public:
Box(double sa, double sb, double sc) {
a = sa;
b = sb;
c = sc;
}
friend double calcVolume(Box bx) {
return bx.a*bx.b*bx.c;
};
};
int main() {
Box a(5.67, 6.43, 7.00),b(90,32.76,44.18);
cout << calcVolume(a)<<endl;
return 0;
}