こんにちは、「this」ポインターの使用方法を理解しようとしています。ここで、クラス BMP のサブクラスであるクラス Image を使用するサンプル プログラムを作成しました。これで、関数 TellWidth と TellHeight が BMP クラスで宣言されました。コンパイラは、TellWidth 関数が Image に存在しないというエラーを表示します。しかし、Image は BMP のサブクラスであるため、BMP の機能を継承するべきではありません。これを解決するにはどうすればよいですか
void Image :: invertcolors()
{
int x;
int y;
int width =(*this).TellWidth();
int height = (*this)->TellHeight();
for(x=0,x<=height-1;x++){
for(y=0,y<=width-1;y++){
(*this)(x,y)->Red = (255 - (*this)(x,y)->Red);
(*this)(x,y)->Blue = (255 - (*this)(x,y)->Blue);
(*this)(x,y)->Green = (255 - (*this)(x,y)->Green);
}
}
delete width;
delete height;
}
画像
class Image : public BMP
{
public:
void invertcolors();
void flipleft();
void adjustbrightness(int r, int g, int b) ;
};
このクラスは大きすぎてここに投稿できません。関連する抜粋を次に示します
class BMP {
private:
int Width;
int Height;
public:
int TellBitDepth(void) const;
int TellWidth(void) const;
int TellHeight(void) const;
};