ヘッダー(.h)ファイルは、主にインターフェイスの指定に関係しています。そこに関数を実装することはできますが、通常はそうしないでください。代わりに、ヘッダーにクラスを定義し、.cppファイル(.hpp、何でも)で実装します。たとえば、あなたのRectangleクラス:
// Rectangle.h
#ifndef RECTANGLE_H
#define RECTANGLE_H
class Rectangle {
public:
// constructors, just initialize our private members
Rectangle(int x, int y, int w, int h)
: _x(x), _y(y), _w(w), _h(h) { }
Rectangle() : _x(0), _y(0), _w(0), _h(0) { }
// implement these in Rectangle.cpp
int get_x();
void set_x(int x);
int get_y();
void set_y(int y);
int get_width();
void set_width(int w);
int get_height();
void set_height(int h);
int Area();
int Perim();
private:
int _x, _y, _w, _h;
};
#endif
// Rectangle.cpp
#include "Rectangle.h"
#include <algorithm>
using std::max;
int Rectangle::get_x() {
return _x;
}
void Rectangle::set_x(int x) {
_x = x;
}
int Rectangle::get_y() {
return _y;
}
void Rectangle::set_y(int y) {
_y = y;
}
int Rectangle::get_width() {
return _w;
}
void Rectangle::set_width(int w) {
_w = max(w, 0);
}
int Rectangle::get_height() {
return _h;
}
void Rectangle::set_height(int h) {
_h = max(h, 0);
}
int Rectangle::Area() {
return _w * _h;
}
int Rectangle::Perim() {
return _w * 2 + _h * 2;
}
それはよく書かれた質問ですが、あなたには、いくつかの教材を読まずにC++のような言語を学ぶことができるようにするつもりはないことに注意してくださいありません。推測とハッキングは将来あなたのプログラミングを傷つけるだけです。私は[このリスト](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)からの初心者の本をお勧めします。あなたの質問に答えて、あなたを守ります。 – GManNickG
+1誰かにコードを渡してもらいたいのではなく、説明を求めるための+1。 –