标签:
环境:
win7 32bits
Visual Studio 2013
参考:https://msdn.microsoft.com/zh-cn/library/4ddd21xh.aspx
错误说明“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();
}
----------------------------------------------------------------------------------------------------------------------
在我自己的代码中如下情况会出现C4930错误:
class mycomparison
{
	bool reverse;
public:
	mycomparison()
	{
		//cout << "construct" << endl;
	}
	mycomparison(bool revparam)
	{
		reverse = revparam;
	}
	
	bool operator() (const int& lhs, const int&rhs) const
	{
		return lhs > rhs;
	//	if (reverse) return (lhs>rhs);
	//	else return (lhs<rhs);
	}
};在主函数中声明优先级队列:
int main()
{
	priority_queue<int, vector<int>, mycomparison>pq(mycomparison());//C4930
	
	system("pause");
	return 0;
}可以做如下两种修改:
第一种方式:
priority_queue<int, vector<int>, mycomparison>pq(( mycomparison() ));//补充括号第二种方式:
priority_queue<int, vector<int>, mycomparison>pq(mycomparison::mycomparison());//补充::访问符号
标签:
原文地址:http://blog.csdn.net/zhangxiao93/article/details/51346627