C++完全なクラスインスタンスとその呼び出し
//
//Rect.h :
class Rect{
private:
int height;
int width;
public:
Rect();
Rect(int,int);
void SetWidth(int);
void SetHeight(int);
int GetHeight();
int GetWidth();
void Print();
};
//Rect.cpp ,
#include "Rect.h"
#include<iostream>
using namespace std;
Rect::Rect()
{
}
Rect::Rect(int a,int b):width(a),height(b)
{
}
void Rect::SetHeight(int x)
{
height=x;
}
void Rect::SetWidth(int x)
{
width=x;
}
int Rect::GetWidth()
{
return width;
}
int Rect::GetHeight()
{
return height;
}
void Rect::Print()
{
cout<<"the Rectangle Height is "<<height<<endl;
cout<<"the Rectangle Width is "<<width<<endl;
cout<<endl;
}
//main.cpp , 。 ,
#include "Rect.h"
int main()
{
Rect a(2,3);
Rect b;
b.SetHeight(4);
b.SetWidth(5);
a.Print();
b.Print();
return 0;
}