C++ で最初のクラスを作成しようとしています。というファイルを作成しgeometryitems.cpp
、これを実行しています:
using namespace std;
class Point
{
double x, y, z;
public:
// constructor
Point(double x, double y, double z)
{
}
// copy constructor
Point(const Point& pnt)
{
x = pnt.x;
y = pnt.y;
z = pnt.z;
}
void display()
{
cout << "Point(" << x << ", " << y << ", " << z << ")";
}
};
次に、次のように別のファイルから呼び出します。
#include <iostream>
#include <cstdio>
#include "geometryitems.cpp"
using namespace std;
int main()
{
// initialise object Point
Point pnt = Point(0, 0, 0);
cout << "Point initialisation:" << endl;
pnt.display();
double t = 0;
cout << endl << t << endl;
Point pnt2 = pnt;
pnt2.display();
// keep the terminal open
getchar();
return 0;
}
出力は次のとおりです。
t
通常の 0 として表示されますが、その他のゼロはその他の数値です。それらが非常に小さな数であったかどうかは理解できますが、非常に大きな数もあります...
のゼロがPoint
奇妙な数字として表示されるのはなぜですか? 通常のゼロのように見せる方法はありますか?