編譯器錯誤 C2660

'function' : 函式不接受數位參數

函式會以不正確的參數數目呼叫。

如果您不小心呼叫 Windows API 函式,而不是同名的 MFC 成員函式,可能會發生 C2660。 若要解決此問題:

  • 調整函式呼叫以符合成員函式呼叫的格式。

  • 使用範圍解析運算子 ( :: ) 告訴編譯器在全域名稱空間中搜尋函式名稱。

範例

下列範例會產生 C2660。

// C2660.cpp
void func( int, int ) {}

int main() {
   func( 1 );   // C2660 func( int ) not declared
   func( 1, 0 );   // OK
}

如果您嘗試直接呼叫 Managed 類型的 Dispose 方法,也可能會發生 C2660。 如需詳細資訊,請參閱 解構函式和完成項 。 下列範例會產生 C2660。

// C2660_a.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 );

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

如果衍生類別隱藏函式,就會發生 C2660。

// C2660b.cpp
// C2660 expected
#include <stdio.h>

class f {
public:
   void bar() {
      printf_s("in f::bar\n");
    }
};

class f2 : public f {
public:
   void bar(int i){printf("in f2::bar\n");}
   // Uncomment the following line to resolve.
   // using f::bar;   // - using declaration added
   // or
   // void bar(){__super::bar();}
};

int main() {
   f2 fObject;
   fObject.bar();
}

如果您不正確地叫用索引屬性,可能會發生 C2660。

// C2660c.cpp
// compile with: /clr
ref class X {
   double d;
public:
   X() : d(1.9) {}
   property double MyProp[] {
      double get(int i) {
         return d;
      }
   }   // end MyProp definition
};

int main() {
   X ^ MyX = gcnew X();
   System::Console::WriteLine(MyX->MyProp(1));   // C2660
   System::Console::WriteLine(MyX->MyProp[1]);   // OK
}

如果您不正確地叫用索引屬性,可能會發生 C2660。

// C2660d.cpp
// compile with: /clr
ref class A{
public:
   property int default[int,int] {
      int get(int a, int b) {
         return a + b;
      }
   }
};

int main() {
   A^ a = gcnew A;
   int x = a[3][5];   // C2660
   int x2 = a[3,5];   // OK
}

如果您在樣板類別中定義新的運算子,可能會發生 C2660,但其中 new 運算子會建立類型不是封入型別的物件。

// C2660e.cpp
// compile with: /c
#include <malloc.h>

template <class T> class CA {
private:
    static T** line;
   void* operator new (size_t, int i) {
      return 0;
   }
   void operator delete(void* pMem, int i) {
      free(pMem);
   }

public:
   CA () { new (1) T(); }   // C2660
   // try the following line instead
   // CA () { new (1) CA<int>(); }
};

typedef CA <int> int_CA;

void AAA() {
   int_CA  list;
}