Compiler warning (level 1) C4930 error

Source: Internet
Author: User

Environment:

Win7 32bits

Visual Studio 2013


Reference: Https://msdn.microsoft.com/zh-cn/library/4ddd21xh.aspx

Error Description "Prototype": the prototype function is not invoked (is it intentionally defined with a variable? )


The following example produces a C4930 error

c4930.cpp//compile with:/w1class Lock {public:   int i;}; void F () {   Lock thelock ();   C4930   //try the following line instead   //Lock Thelock;} int main () {}

C4930 also occurs when the compiler cannot distinguish between function prototype declarations and function calls.

c4930b.cpp//compile with:/ehsc/w1class 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 ();}

in the example above, the result of a method without parameters is passed as a parameter to the constructor of the unnamed local class variable. The call is ambiguous: it can be either a named local variable or a method call prefixed with the object instance and the corresponding pointer operator to the member.


--------------------------------------------------------------------------------------------------------------- -------


In my own code, C4930 errors occur in the following situations:

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);//els e return (LHS<RHS);};
declare the priority queue in the main function:

int main () {priority_queue<int, vector<int>, Mycomparison>pq (Mycomparison ());//c4930system ("pause"); return 0;}

I thought I created a temporary variable, and the compiler could understand it as a function declaration, the return value is Priority_queue, the function name is PQ, and the parameter is a pointer to the functions that omit the specific return type.

There are two types of modifications that can be made:

The first way:

Priority_queue<int, Vector<int>, Mycomparison>pq ((Mycomparison ()));//Supplementary brackets
The second way:

Priority_queue<int, Vector<int>, Mycomparison>pq (Mycomparison::mycomparison ());//Add:: Access symbol

Reference: http://stackoverflow.com/questions/12041509/possible-compiler-bug-for-c4930





Compiler warning (level 1) C4930 error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.