c++ Why can't I pass up types CDC and CBitmap into another class's parameters?

I am trying to setup parameter from one class into another. But for types CDC and CBitmap, it won't let me??

dcMem and m_bmp are instance variables or the parameters in the class

(also note that I am using vc++ 6.0)

error C2582: 'CDC' : 'operator =' function is unavailable
error C2582: 'CBitmap' : 'operator =' function is unavailable


Image::Set_dcMem(CDC _dcMem)
    dcMem = _dcMem;


Image::Set_m_bmp(CBitmap _m_bmp)    
    m_bmp = _m_bmp;

I had also tried just setting the parameters as such from the other class but got the same errors listed above:

Image *pImage = new Image;
pImage->dcMem = dcMem;
pImage->m_bmp = m_bmp;

I found this links, but not sure how to apply:



with the correction from down below:

CDC* dcMem;
CBitmap *m_bmp;

Image *pImage = new Image;
pImage->dcMem = &dcMem;
pImage->m_bmp = &m_bmp;


When you assign an object using = the object is copied, the variable on the left is already instantiated, so it must somehow get a copy of the state of the object on the right side of the assignment.

But sometimes it is difficult to copy an object. In some cases it is because some of the internal data members of the object cannot be copied, or because it is difficult or time consuming to copy them.

In any case, when the author of a class decides that copies will not work for that class, he/she undefines the operator= method, to prevent users of the class from ever trying to assign objects of that class. See this question for some additional information on this.

But this isn't a huge problem. Normally, for objects of this kind you don't really want to be happily triggering copies of objects anyway. Instead, what you want to do is work with references and pointers.

class Image {
    CDC* dcMem; // <-- declare member variable as a reference

Image::Set_dcMem(CDC& _dcMem) // <-- pass references instead of objects
    dcMem = &_dcMem; // <-- you can assign references just fine

Need Your Help

Drawing-application with SurfaceView (android)

android draw surfaceview blinking

i have a problem with simple drawing application on android,

Can I (re-) map commands in vim?


I love vim and the speed it gives me. But sometimes, my fingers are too speedy and I find myself typing ":WQ" instead of ":wq" (on a German keyboard, you have to press shift to get the colon). Vim ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.