I am trying to write a simple try/catch statement, but I keep on getting compiler errors. This is my code:
int divide(int x, int y)
{
if (y == 0) {
throw 0;
}
return x / y;
}
Exception::Exception()
{
try {
cout << divide(10, 0) << "\n";
} catch (int e) {
cout << "Cannot divide by " << e << "\n";
}
}
I am getting the following compiler errors:
LNK2019: unresolved external symbol “public: int_thiscall Exception::divide(int,int” (?divide@Exception@@QAEHH@Z) referenced in function “public:_thiscall Exception::Exception(void)”(??0Exception@@QAE@XZ)
LNK1120: 1 unresolved externals
My magic remote debugging skills tell me that
divideis a member ofException, but you’re defining it in the global namespace. PrefixdividewithException::, a la