は、私は最近C++で別のクラスファイルをいじり始め、これが私の最初の試みであった:C++クラスのヘッダーと実装エラー
//ThisClass.h
#ifndef THISCLASS_H
#define THISCLASS_H
class ThisClass
{
private:
int x;
float y;
public:
ThisClass(int x, float y);
void setValues(int x, float y);
int printX();
float printY();
};
#endif // THISCLASS_H
:
まず私は「ThisClass.h」と呼ばれるクラスのヘッダを作りました
はその後、私は「ThisClass.cpp」と呼ばれるファイルに私のクラスを実装:
//ThisClass.cpp
#include "ThisClass.h"
ThisClass::ThisClass(int x, float y)
{
this->x = x;
this->y = y;
}
void ThisClass::setValues(int x, float y)
{
this->x = x;
this->y = y;
}
int ThisClass::printX()
{
return this->x;
}
float ThisClass::printY()
{
return this->y;
}
は最後に、私はクラスを使用し、「main.cppに」というファイルを作っ:
//main.cpp
#include <iostream>
using namespace std;
int main()
{
ThisClass thing(3, 5.5);
cout << thing.printX() << " " << thing.printY()<< endl;
thing.setValues(5,3.3);
cout << thing.printX() << " " << thing.printY()<< endl;
return 0;
}
私は、コンパイルされ、MinGWのコンパイラを使用したコードブロックでこのプログラムを実行し、次のエラーを受け取った:
In function 'int main()':|
main.cpp|7|error: 'ThisClass' was not declared in this scope|
main.cpp|7|error: expected ';' before 'thing'|
main.cpp|8|error: 'thing' was not declared in this scope|
||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
私は何とかこの間違っているのでしょうか?どんな助けもありがとう。
これは私のエラーを修正しました。しかし、私は2つの叫び声があっても私のコンソールは何も出力していません。 –
どのコンソールですか? Visual StudioなどのIDEを使用していますか、コマンドラインだけですか? – SurvivalMachine
私はMinGWコンパイラを使用するコードブロックを使用しています。 –