Anteckning
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
"prototyp": en prototypfunktion som inte anropas (var en variabeldefinition avsedd?)
Anmärkningar
Kompilatorn identifierade en oanvänd funktionsprototyp. Om prototypen var avsedd som en variabeldeklaration tar du bort parenteserna öppna/stäng.
Examples
I följande exempel genereras 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 kan också inträffa när kompilatorn inte kan skilja mellan en funktionsprototypdeklaration och ett funktionsanrop.
I följande exempel genereras 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();
}
I exemplet ovan skickas resultatet av en metod som tar noll argument som ett argument till konstruktorn för en icke namngiven lokal klassvariabel. Anropet kan vara tvetydigt genom att antingen namnge den lokala variabeln eller prefixa metodanropet med en objektinstans tillsammans med lämplig operator för pekare till medlem.