About error C2248

  • Thread starter Thread starter Frank
  • Start date Start date
F

Frank

Hello!
I defined a class(CMyView1) based on CView from class wizard in VC2005, and
there're following code in .h file:

....
....
protected:
CMyView1(); // protected constructor used by dynamic creation
virtual ~CMyView1();
....
....

and then in MainFrm.cpp , there're

....
....
CView* pView = (CView*) new CMyView1; // error C2248
....
....

then the complier reported a error c2248, "cannot access protected member
declared in class 'CMyView1'", how do I solve the problem?

shall I just change the "protected" to "public" ? what's the meaning for the
comment line ? (protected constructor used by dynamic creation)

Thanks a lot!
Frank
 
Hi Frank,
How do I solve the problem? shall I just change the "protected" to "public"
?
E.g. be creating a public method returning the class instance.

public CView* CreateCView()
{
return new CMyView1(); // being inside of class it accesses any his
members
}
what's the meaning > for the comment line ? (protected constructor used by dynamic
creation)
It's like the example above - doesn't allow you to create the object manualy,
only by using "factories" or such.

Regards, Alex
[TechBlog] http://devkids.blogspot.com
 
Back
Top