環境
- Windows10
- CLion 2018.1 (C++17)
やりたいこと
簡単なヘッダファイルを作って使ってみたい
#試したこと
次のようなヘッダファイルとC++ファイルを作成しました
Cpp
1#pragma once 2 3// Math class definition 4static class Math 5{ 6public: 7 8 // given base and exponent, calculate value 9 static int Math::pow(int base, int exp); 10 11};
Cpp
1#include "Math.h" 2 3int Math::pow(int base, int exp) 4{ 5 int result = 1; 6 7 for (int i = 0; i < exp; i++) 8 { 9 result = result * base; 10 } 11 12 return result; 13}
これを次のようにして使用しようとしました。
Cpp
1#include "Math.h" 2#include <iostream> 3 4using namespace std; 5 6int main() 7{ 8 int result = Math::pow(2, 10); 9 10 cout << result << endl; 11 12 return 0; 13}
最初はerror: extra qualification 'Math::' on member 'pow' [-fpermissive]
というのが出てきて、調べた結果、参考にしたサイトがVisual Studioを使うことを前提にしていることがわかり、Math.h
のMath::
を削除しました。
しかし、ここを直してもerror: a storage class can only be specified for objects and functions
というエラーができてしまいます。いろいろ調べてstatic
周辺あたりに問題があるのかな?位のところまではわかったのですが、それ以上がわかりません。
C++
初心者でエラーの意味すら調べてもまだわからない状態なのでエラーの意味から教えていただけると助かります。よろしくお願いします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/04/07 14:35