Bagikan melalui


Compiler Warning (level 1) C4930

'prototipe': fungsi yang diprototi tidak disebut (apakah definisi variabel dimaksudkan?)

Pengkompilasi mendeteksi prototipe fungsi yang tidak digunakan. Jika prototipe dimaksudkan sebagai deklarasi variabel, hapus tanda kurung buka/tutup.

Sampel berikut menghasilkan C4930:

// C4930.cpp
// compile with: /W1
class Lock {
public:
   int i;
};

void f() {
   Lock theLock();   // C4930
   // try the following line instead
   // Lock theLock;
}

int main() {
}

C4930 juga dapat terjadi ketika kompilator tidak dapat membedakan antara deklarasi prototipe fungsi dan panggilan fungsi.

Sampel berikut menghasilkan C4930:

// C4930b.cpp
// compile with: /EHsc /W1

class BooleanException
{
   bool _result;

public:
   BooleanException(bool result)
      : _result(result)
   {
   }

   bool GetResult() const
   {
      return _result;
   }
};

template<class T = BooleanException>
class IfFailedThrow
{
public:
   IfFailedThrow(bool result)
   {
      if (!result)
      {
         throw T(result);
      }
   }
};

class MyClass
{
public:
   bool MyFunc()
   {
      try
      {
         IfFailedThrow<>(MyMethod()); // C4930

         // try one of the following lines instead
         // IfFailedThrow<> ift(MyMethod());
         // IfFailedThrow<>(this->MyMethod());
         // IfFailedThrow<>((*this).MyMethod());

         return true;
      }
      catch (BooleanException e)
      {
         return e.GetResult();
      }
   }

private:
   bool MyMethod()
   {
      return true;
   }
};

int main()
{
   MyClass myClass;
   myClass.MyFunc();
}

Dalam sampel di atas, hasil metode yang mengambil argumen nol diteruskan sebagai argumen ke konstruktor variabel kelas lokal yang tidak disebutkan namanya. Panggilan dapat dibedakan dengan menamai variabel lokal atau awalan panggilan metode dengan instans objek bersama dengan operator pointer-to-member yang sesuai.