ライブラリのpow
関数をよく使用するアプリケーションを作成しました。累乗を簡単かつ高速にするためmath.h
に、オーバーロードを試みました。operator^
私はこのコードを書きました:
#include <iostream>
#include <math.h>
using namespace std;
int operator^(int, int); // line 6
int main(int argc, char * argv[]) { /* ... */ }
int operator^(int a, int n) // line 21
{
return pow(a,n);
}
コンパイラ (Linux で g++ を使用) から次のエラーが返されました。
main.cpp:6:23: エラー: 'int operator^(int, int)' にはクラスまたは列挙型の引数が必要です main.cpp:21:27: エラー: 'int operator^(int, int)' が必要ですクラスまたは列挙型の引数を持つ