Definite VC++ Compiler Issue

G

Guest

Perhaps many have heard of the famous C3767 "Candidate functions...."

I found that by not using a native type (struct ptr) in a constructor
signature, the problem went away. The problem only occurred when calling one
assembly from another with both assemblies using /clr.

When using the constrctor from another class in the same source file, there
is no error at all.

Assembly A
-------------

struct test_native {int n;};

public ref Class_xyz
{
public:
struct test_native *p;

Class_xyz(struct test_native *p)
{
this->p = p;
}
}


Assembly B
--------------

struct test_native {int n;} native_struct;

public ref class_uvw
{
public:

Class_xyz^ xyz;

class_uvw( )
{
xyz = gcnew Class_xyz(&native_struct);
}
}

The above causes C3767.


Now, if in Class_xyz another constructor is defined as follows:

Assembly A
-------------

struct test_native {int n;};

public ref Class_xyz
{
public:

struct test_native *p;

Class_xyz(struct test_native *p)
{
this->p = p;
}

int n;

Class_xyz(int n)
{
this->n = n;
}
}

Then the error changes to C22248 "Cannot access private member..."

To top it off, if the native struct is defined as public in both assemblies
as:
public struct test_native {int n;};

Then the compiler error goes away completely!

So I see two or three compiler errors/issues here:

1. C3767 explanation in help refers to friend classes but this has nothing
to do with friend classes.

2. Adding additional constructor with different signature changes error to
C2248 when this additional signature has nothing to do with the other one.

3. Why does Assembly B compile with no errors at all when change the structs
to public?
 
A

Arnaud Debaene

Greg said:
Perhaps many have heard of the famous C3767 "Candidate functions...."
Then the error changes to C22248 "Cannot access private member..."
<snip>

The guts of these errors is that, in VS2005, metadata for native structs and
classes in mixed mode asssemblies is private, so a native class can't be
used in a nother assembly. To solve that, either make the native type public
(as you already have found), or use #pragma make_public on test_native if
you can't modify the native class definition.

In your code, there is of course another error wich is that you define twice
the test_native class, therefore breaking the ODR (you don't break really
anything here, since the 2 definitions are the same, but it's a bad idea
anyway).

Arnaud
MVP - VC
 

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