I wrote an application in which I often use a function powfrom the library math.h. I tried to overload operator^to simplify and speed up the exposure. I wrote this code:
#include <iostream>
#include <math.h>
using namespace std;
int operator^(int, int);
int main(int argc, char * argv[]) { }
int operator^(int a, int n)
{
return pow(a,n);
}
The compiler (I used g ++ on Linux) returned these errors to me:
main.cpp: 6: 23: error: 'int operator ^ (int, int) must have an argument to the class or enumerated type main.cpp: 21: 27: error:' int operator ^ (int, int) must have an argument to the class or enumerated type
source
share