共用方式為


編譯器警告 (層級 1) C4930

'prototype':未呼叫原型函式 (是否打算使用變數定義?)

編譯程式偵測到未使用的函式原型。 如果原型是做為變數宣告,請移除開啟/關閉括弧。

下列範例會產生 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。

下列範例會產生 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();
}

在上述範例中,採用零自變數的方法結果會當做自變數傳遞至未命名局部類別變數的建構函式。 呼叫可藉由命名局部變數,或使用對象實例加上方法呼叫前置詞,以及適當的指針對成員運算符來釐清呼叫。