Definite VC++ Compiler Issue

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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?

--
Greg McPherran
www.McPherran.com
.



Relevant Pages

  • Re: How to initialize a member struct
    ... I can't give this struct a constructor. ... class constructor (call it "TemplatedClass") in another DLL library. ... This leaves me with trying to come up with a way to initialize ...
    (microsoft.public.dotnet.languages.vc)
  • Re: C++ Compiler behavior regarding struct constructors
    ... > struct default constructor ... underlying class type shall have a user-declared default constructor. ... MyStruct, that default constructor zero-fills the memory. ... if you need initialization, ...
    (microsoft.public.dotnet.languages.vc)
  • Re: C++ user-defined new (expert question)
    ... I don't see here a reason to put the default/non-default constructor into ... typedef struct { ... MYPOINT * MYPOINT_new ... void MYPOINT_free ...
    (microsoft.public.vc.mfc)
  • Re: TREE structure in MFC, how, where and why?
    ... Your struct contains a CString object, which is a C++ class with various ... By using malloc, the constructor on your CString is not being called. ...
    (microsoft.public.vc.mfc)
  • Typecasting portability in C
    ... What I am trying to do is implement polymorphism in C. ... void* but then typecast it and get the signature out of the object. ... struct SomeObjectType { ... again what about portability. ...
    (comp.lang.c)