Re: Help With Copy Constructor.
I tried what you sugested the program still crashes. What am I doing
wrong?
#include<windows.h>
#include<vector>
#include<iostream>
#include<string>
using namespace std;
#ifndef GRAPHIC_H
#define GRAPHIC_H
class graphic{
int btmap;
int lr,ud; //Diminsion (size) of the graphic
vector<BYTE>gdata;
HBITMAP hbitmap;
BITMAP bitmap;
HDC hdc, hdcmem;
void copy(const BYTE in[]);
BYTE get(int n)const {return gdata[n];}
vector<BYTE>vGet() const {return gdata;}
public:
graphic();
graphic(const BYTE c[]);
graphic(const graphic&);
graphic& operator = (const graphic&);
void SetGr(const BYTE c[]);
void set(const BYTE c[]);
void display(HWND,const int, const int);
};
#endif
#include<windows.h>
#include<fstream>
#include<string>
#include<vector>
#include "graphic.h"
using namespace std;
void graphic::copy(const BYTE in[]){
for(int lp=0; lp != 32; lp++)
gdata.push_back(in[lp]);
}
void graphic::SetGr(const BYTE c[]){
//Changing the graphic
copy(c);
BITMAP bitmap = {0,ud,lr,2,1,1};
bitmap.bmBits = &gdata[0];
hbitmap = CreateBitmapIndirect(&bitmap);
}
graphic::graphic(const graphic& gr){
ud = lr = 16;
//memcpy( gdata, gr.gdata, 32 );
gdata = gr.vGet();
BITMAP bitmap = {0,ud,lr,2,1,1};
bitmap.bmBits = &gdata[0];
hbitmap = CreateBitmapIndirect(&bitmap);
}