473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

About error C2248

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
Sep 29 '07 #1
1 1467
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
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

Sep 29 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Zealot | last post by:
class Base { protected: int var; }; class ChildB : public Base {}; class ChildA : public Base
1
by: Bronek Kozicki | last post by:
I've received following code snipped from some mailing list: 1 class A 2 { 3 private: 4 A(); 5 protected: 6 A(int x) {} 7 public: 8 virtual ~A() {}
24
by: Noah Roberts | last post by:
Item #1 in the More Exceptional C++ book uses the following construct: fstream in; .... process( in.is_open() ? in : cin,...); Where process has been shown as having various multiple...
3
by: NKH | last post by:
Hi, I am trying to recompile application that has been developed in VC++ 6.0 with VC++2005.. While compiling, I'm getting the following error.. error C2248: 'CObject::CObject' : cannot...
8
by: SilverJester | last post by:
I'm getting the following error when trying to compile my code: Not sure what it means, but it didn't start until after I added the "read_file" function (btw I know the function is mostly...
9
by: fcvcnet | last post by:
Hi, I write a class class CSegment { public: CSegment(void); public: ~CSegment(void); public: CArray< CList< CPoint, CPoint& >, CList< CPoint, CPoint& >& m_curve;
2
by: KevinMurphyRJLG | last post by:
I have a managed C++ class with a number of static methods, all of which are declared public. After switching from .NET 1.1 to 2.0 (Visual Studio 2003 to VS 2005), I'm now getting compiler...
1
by: Colonel | last post by:
I overloaded the operator "<<" via friend function, but it doesn't work. The errors say that can't access the private member, don't the friend functions have the rights to access the private...
4
by: AngreGanon | last post by:
Hi, all~ ^^ If i use #1 OK, but use # 2 error happend what's different? #include <iostream> /* -----------# 1------------ using std::endl; using std::cout; using std::ostream;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.