Aracılığıyla paylaş


Derleyici Hatası C2039

'identifier1' : is not a member of 'identifier2'

Kod yanlış bir şekilde bir yapı, sınıf veya birleşim üyesini çağırır veya buna başvurur.

Örnekler

Aşağıdaki örnek C2039 oluşturur:

// C2039.cpp
struct S {
   int mem0;
} s, *pS = &s;

int main() {
   pS->mem1 = 0;   // C2039 mem1 is not a member
   pS->mem0 = 0;   // OK
}

Aşağıdaki örnek C2039 oluşturur:

// C2039_b.cpp
// compile with: /clr
using namespace System;
int main() {
   Console::WriteLine( "{0}", DateTime::get_Now());   // C2039
   Console::WriteLine( "{0}", DateTime::Now);   // OK
   Console::WriteLine( "{0}", DateTime::Now::get());   // OK
}

Aşağıdaki örnek C2039 oluşturur:

// C2039_c.cpp
// compile with: /clr /c
ref struct S {
   property int Count {
     int get();
     void set(int i){}
   };
};

int S::get_Count() { return 0; }   // C2039
int S::Count::get() { return 0; }   // OK

Varsayılan dizin oluşturucuya yanlış erişmeye çalıştığınızda da C2039 oluşabilir. Göstermek için, bu kod aşağıdaki C++/CLI kodu tarafından kullanılan bir C# bileşenini tanımlar:

// C2039_d.cs
// compile with: /target:library
// a C# program
[System.Reflection.DefaultMember("Item")]
public class B {
   public int Item {
      get { return 13; }
      set {}
   }
};

Aşağıdaki örnek, C++/CLI'dan önceden tanımlanmış C# bileşeninin varsayılan dizin oluşturucusunu yanlış kullandığında C2039 oluşturur:

// C2039_e.cpp
// compile with: /clr
using namespace System;
#using "c2039_d.dll"

int main() {
   B ^ b = gcnew B;
   int n = b->default;   // C2039
   // try the following line instead
   // int n = b->Item;
   Console::WriteLine(n);
}

Genel değerler kullanıyorsanız C2039 da oluşabilir. Aşağıdaki örnek C2039 oluşturur:

// C2039_f.cpp
// compile with: /clr
interface class I {};

ref struct R : public I {
   virtual void f3() {}
};

generic <typename T>
where T : I
void f(T t) {
   t->f3();   // C2039
   safe_cast<R^>(t)->f3();   // OK
}

int main() {
   f(gcnew R());
}

Yönetilen veya yönetilmeyen kaynakları serbest bırakmaya çalıştığınızda C2039 oluşabilir. Daha fazla bilgi için bkz . Yıkıcılar ve sonlandırıcılar.

Aşağıdaki örnek C2039 oluşturur:

// C2039_g.cpp
// compile with: /clr
using namespace System;
using namespace System::Threading;

void CheckStatus( Object^ stateInfo ) {}

int main() {
   ManualResetEvent^ event = gcnew ManualResetEvent( false );
   TimerCallback^ timerDelegate = gcnew TimerCallback( &CheckStatus );
   Timer^ stateTimer = gcnew Timer( timerDelegate, event, 1000, 250 );

   ((IDisposable ^)stateTimer)->Dispose();   // C2039

   stateTimer->~Timer();   // OK
}