Discussion:
why I can't declaring a CArray object in a separate header file?
(too old to reply)
Electronic75
2008-10-24 16:26:13 UTC
Permalink
Hello I have no problem declaring a CArray variable inside a class definition
but as I have a separate file that I place all my typedefs inside it, I have
tried to define a struct that has a CArray member but compiler says:

Error 1 error C2248: 'CObject::CObject' : cannot access private member
declared in class 'CObject' c:\program files\microsoft visual studio
8\vc\atlmfc\include\afxtempl.h 272

this was my code inside TypeDefs.H

typedef struct tag_compliance_info
{
LONG lModuleCode;
LONG lModuleVersion;
CString sModuleName;
CArray<POINT> aCompliance;
} STRUCT_COMPLIANCE_INFO;

I use visual Studio 2005
What is the reason and How can I solve this?
David Wilkinson
2008-10-24 16:41:26 UTC
Permalink
Post by Electronic75
Hello I have no problem declaring a CArray variable inside a class definition
but as I have a separate file that I place all my typedefs inside it, I have
Error 1 error C2248: 'CObject::CObject' : cannot access private member
declared in class 'CObject' c:\program files\microsoft visual studio
8\vc\atlmfc\include\afxtempl.h 272
this was my code inside TypeDefs.H
typedef struct tag_compliance_info
{
LONG lModuleCode;
LONG lModuleVersion;
CString sModuleName;
CArray<POINT> aCompliance;
} STRUCT_COMPLIANCE_INFO;
I use visual Studio 2005
What is the reason and How can I solve this?
Electronic:

You must be doing something that causes your struct to be copied. The default
copy constructor will require a copy constructor for your CArray, which in turn
requires a copy constructor for CObject.

IMO, by far the best way to deal with this is to use std::vector instead of CArray.
--
David Wilkinson
Visual C++ MVP
Tom Serface
2008-10-24 16:44:35 UTC
Permalink
Couple of things to check:

1. Do you have enough included for the definition of CArray and POINT to be
found?
2. Is there another typedefs.h file somewhere that may be goofing you up?

I've never tried to do this sort of thing in a typedef (mostly use classes
in classes) so I may be way off. Is there any reason this can't just be a
class as well?

Tom
Post by Electronic75
Hello I have no problem declaring a CArray variable inside a class definition
but as I have a separate file that I place all my typedefs inside it, I have
Error 1 error C2248: 'CObject::CObject' : cannot access private member
declared in class 'CObject' c:\program files\microsoft visual studio
8\vc\atlmfc\include\afxtempl.h 272
this was my code inside TypeDefs.H
typedef struct tag_compliance_info
{
LONG lModuleCode;
LONG lModuleVersion;
CString sModuleName;
CArray<POINT> aCompliance;
} STRUCT_COMPLIANCE_INFO;
I use visual Studio 2005
What is the reason and How can I solve this?
Electronic75
2008-10-24 16:58:25 UTC
Permalink
David,
you were right! problem solved! thank you.

Tom,
Well, I can wrap it in a class but because I do not need any function I
thought a separate class maybe an overkill, thank you

Thank you both of you very much
Tom Serface
2008-10-24 18:03:55 UTC
Permalink
Glad you got it to work.

Tom
Post by Electronic75
David,
you were right! problem solved! thank you.
Tom,
Well, I can wrap it in a class but because I do not need any function I
thought a separate class maybe an overkill, thank you
Thank you both of you very much
Loading...