?
Solved

Error C2248: cannot access private struct declared in class

Posted on 2006-10-27
4
Medium Priority
?
429 Views
Last Modified: 2008-01-16
Hi expert,

I don't understand why the following code is not able to compile on Windows, I was able to compile it on redhat 3.0.

ClassFreeMem<ClassOne::ClassTwo>*
      ClassOne::ClassTwo::freememory= 0;
ClassFreeMem<ClassOne>* coneClass::freememory= 0;
struct InitFreeMemPtrs
{
   InitFreeMemPtrs(void)       // Default constructor.
   {
      // Allocate the freestore in the correct order.
      ClassOne::ClassTwo::freememory= new ClassFreeMem<ClassOne::ClassTwo>;  -> compile error here C2248
      ClassOne::freememory= new ClassFreeMem<ClassOne>;
   }

   ~InitFreeMemPtrs(void)      // Default destructor.
   {
      // Delete the freestore in the correct order.
      delete ClassOne::freememory;
      delete ClassOne::ClassTwo::freememory;  -> compile error here C2248
   }
};

InitFreeMemPtrs InitFreeMem;


ClassOne
{
public:
 static FlFreeStoreClass<ClassOne>* freememory;
private:
struct ClassTwo
{
static ClassFreeMem<ClassTwo>* freememory;
}
}


If I move the struct ClassTwo in the public area, then I am able to compile.  At this point, I would like to find a better solution than moving the struct ClassTwo to public.  Why this is able to compile on Linux, but not windows?

Looking foward to hear from you.
0
Comment
Question by:4eyesgirl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 17820359
I am not sure why that compiles on Linux (it shouldn't), but making 'InitFreeMemPtrs' a 'friend' of 'ClassOne' should work, i.e.

ClassOne
{
friend struct InitFreeMemPtrs;
public:
 static FlFreeStoreClass<ClassOne>* freememory;
private:
struct ClassTwo
{
static ClassFreeMem<ClassTwo>* freememory;
}
}


0
 

Author Comment

by:4eyesgirl
ID: 17820520
Jkr -

Do you know the compile did let this line of code compile?  
ClassFreeMem<ClassOne::ClassTwo>*
      ClassOne::ClassTwo::freememory= 0;
What is the difference between this one than the one in the constructor?


0
 
LVL 86

Expert Comment

by:jkr
ID: 17820641
Shouldn't compile either, but may (erroneously) look like a static member initializer to the compiler. Weird.
0
 

Author Comment

by:4eyesgirl
ID: 17820648
Thanks jkr.

As alwasy - you are a great help!!!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question