Bug in compiler:Cannot box/unbox private structures declared in a MG C++ class

Y

Yuan Ze

The compiler can not compile the code boxing/unboxing value types declared
in a MG C++ class. It reports compiler error 2248, 'member' : cannot
access member declared in class 'class'. To use a "private" value type in a
MG C++ class, I have to make it public. Can anyone tell me if VS2005 has
fixed this problem? Thanks.

Here is the code for testing:

namespace testing
{
__value struct OuterB
{
public:
int i;
};

public __gc class A
{
private:
__value struct InnerB
{
public:
int i;
};

public:
__value struct InnerPublicB
{
public:
int i;
};

public:
void Test()
{
//inner private:error C2248
InnerB innerB;
__box InnerB* pObject=__box(innerB);
InnerB unboxedObject=*__try_cast<__box InnerB*>(pObject);
//error C2248
__box InnerB* pObject2;
InnerB unboxedObject2=*__try_cast<__box InnerB*>(pObject2);
//error C2248

//inner public:OK
InnerPublicB innerPublicB;
__box InnerPublicB* pinnerPublicB=__box(innerPublicB);
InnerPublicB unboxedinnerPublicB=*__try_cast<__box
InnerPublicB*>(pinnerPublicB);

//outer:OK
OuterB outerB;
__box OuterB* pOuterB=__box(outerB);
OuterB unboxedouterB=*__try_cast<__box OuterB*>(pOuterB);
}//A::Test
};//class A

}//namespace testing
 
D

David Lowndes

The compiler can not compile the code boxing/unboxing value types declared
in a MG C++ class. It reports compiler error 2248, 'member' : cannot
access member declared in class 'class'. To use a "private" value type in a
MG C++ class, I have to make it public. Can anyone tell me if VS2005 has
fixed this problem?

It doesn't appear to be any different. It gives this error:

error C2248: 'testing::A::InnerB' : cannot access private struct
declared in class 'testing::A'

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top