CGdiObject error C4482

While compiling a project that 100% clean compiles under VC6, I am getting the following error:

e:\program files\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(259) : error C2248: 'CObject::operator =' : cannot access private member declared in class 'CObject'

e:\program files\microsoft visual studio 8\vc\atlmfc\include\afx.h(540) : see declaration of 'CObject::operator ='

e:\program files\microsoft visual studio 8\vc\atlmfc\include\afx.h(510) : see declaration of 'CObject'

This diagnostic occurred in the compiler generated function 'CGdiObject &CGdiObject::operator =(const CGdiObject &)'

There is no reference to the line of code in my project that is provoking this error. The CPP file listed immediately before this error does not use in itself any GDI objects. I have tried compiling with various listings enabled to try to locate what is provoking the error but am making no progress.

Any ideas anyone?

[997 byte] By [Tim42] at [2007-12-16]
# 1

Hi,

Quickly browsing through sources, I do not see any code change that can cause this error. Could you show code snippet that causes this error? Look for use of operator = in classes that subclass CGdiObject().

Thanks,
Nikola
VC++ Team

NikolaDudar at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ General...
# 2
Thats the problem - there are no GDI related classes in the cpp or .h file preceeding. All the .h files included are included elsewhere for other cpp files - about 1500 of them in total. Removing the preceeding cpp file removes the error. I have searched the entire project for CPen, CBrush etc - there are very few as it is an MDI Property Sheet / Page / Dialog based database client server app (IE very little GDI).

So, to recap. This was a MSVC6 project (still is, this is a test run at conversion / learning exercise) that compiled 100% ok under vc6 and vc8. I then added CLR support with a hand ful of errors (one with HTREEITEM) and this error + a 35MB debug executable. (The release build comes in under 3 mb normally). The IDE has bloated to 7-800MB during the compile...

Are there any switches to produce the expanded C++ code for this 1 file? I tried some settings and one produced a 6+MB file that I searched for GDI objects in without success. The cpp file concerned is only a few hundred lines.

Ideas?

Tim42 at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ General...
# 3
Hi,

Could you please try separating this cpp file from the rest of the project and compile it? Will it still give same errors?

Is it possible if you email me this file? Try zip it and email it to nikolad on microsoft dot com.

Thanks,
Nikola

NikolaDudar at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ General...
# 4
Thanks,

I'll work towards that: add the file back in and try blocking code chunks until I find the offender & if that fails, pull out the cpp and do as you say.

- Tim

Tim42 at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ General...
# 5

Tim,

Look for similar pattern:


class CReproClass {public:CReproClass::CReproClass(void) {}CReproClass::~CReproClass(void) {}CPen m_pen; //or any other class that subclasses CGdiObject};


or


class CReproClass : public CPen{...
};



then is later used in
CReproClass a;
CReproClass b;
a = b;

This is the cause of your problem.

Thanks,
Nikola

NikolaDudar at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ General...
# 6
Thanks. That is correct. Mitch forwarded the evidence yesterday. The main issue remaining is the error reporting.
Thanks again.
Tim42 at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ General...