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?
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?