This documentation is archived and is not being maintained.

Compiler Error C3815

Error Message

return type of method 'get_accessor' must match type of the last parameter of a setter

When declaring properties, the return value of the get_accessor method must match the last parameter in the declaration of the set accessor method.

C3815 is only reachable using /clr:oldSyntax.

The following sample generates C3815:

// C3815.cpp
// compile with: /clr:oldSyntax /LD
#using <mscorlib.dll>
__gc class X
   __property char get_N()
   // try the following line instead
   // __property int get_N()
      return m_val;

   __property void set_N( int val)
      m_val = val;

   int m_val;
};   // C3815

The following sample shows how you can overload properties, so that the return type of the getter does not match the last parameter of the setter.

// C3815b.cpp
// compile with: /clr:oldSyntax /c
#using <mscorlib.dll>
public __gc class MyClass {
// 1st property:
   __property System::Int32 get_p1();
   __property void set_p1(System::Int32 i);

// 2nd property (only setter):
   __property void set_p1(System::Int32* i);