As a part of an assignment I am to construct a copy constructor for a bitmap loader/manipulator class. 2 of the things that must be copied are struct headers (containing a bunch of useless bitmap information, with a tiny bit of useful stuff).
Image Headerfile:
#pragma once
#include "Drawer.h"
#include <iostream>
using namespace std;
class CImager
{
bool LoadFile (char * const);
bool DoDMA (void);
void DoFree();
void DoError(int, char * const, ostream & const = cerr) const;
BITMAPFILEHEADER * BMPFileHead;
BITMAPINFOHEADER * BMPInfoHead;
RGBTRIPLE * RGBVal;
DWORD Pixels;
int _iHeight,
_iWidth;
public:
void Blur();
RGBTRIPLE BlurVal(int, int);
void Write(char * const szFilename = "save.bmp");
void EnhanceRed();
void SwapRB();
CImager(char * const);
void Render() const;
CImager(CImager &);
~CImager(void);
};
The CCTor (so far)
CImager::CImager(CImager & objCopy)
{
BMPInfoHead = 0;
BMPFileHead = 0;
if (objCopy.BMPFileHead) //make sure that the object has some meat to copy
{
DoDMA(); //allocate memory for the headers
BMPInfoHead = objCopy.BMPInfoHead;
BMPFileHead = objCopy.BMPFileHead;
RGBVal = new RGBTRIPLE [objCopy.Pixels];
for (int i = 0; i < objCopy.Pixels; ++i)
RGBVal[i] = objCopy.RGBVal[i];
}
}
This fails miserably because BMPInfoHead points to the same location as objCopy.BMPInfoHead. Therefore it is not a true copy, just another pointer pointing to the original pointer's data. But there's about 20 members in each of these headers, and I think it would be rediculous to have to copy each one independently. I'm looking for a fast, preferably 1 line, method of copying entire structs. If you need more information/code, don't hesitate to ask. Thanks!