The brackets before the obviously called expression must have (pointer) function type compiler error C2064, compiler c2064

Source: Internet
Author: User

The brackets before the obviously called expression must have (pointer) function type compiler error C2064, compiler c2064

When I saw the phrase "the parentheses before the obviously called expression must have (pointer) function type", I found that my language level is poor and I cannot understand it at all, it took only half a day to know what went wrong.

A simple example

Class CTest {void (CTest: * m_pFun) (); void CallFun () {(this-> * m_pFun) (); // OK, the object pointer and function name must be enclosed in parentheses. The * sign (this-> * m_pFun () must be added before the function name; // error (this-> m_pFun )(); // error} // link to this article: http://www.cnblogs.com/vcpp123/p/5902839.html };

 

For more information, see MSDN. Link: https://msdn.microsoft.com/query/dev14.query? AppId = Dev14IDEF1 & l = ZH-CN & k = k (C2064) & rd = true

Compiler error C2064

Term does not evaluate to a function taking N arguments

A call is made to a function through an expression. The expression does not evaluate to a pointer to a function that takes the specified number of arguments.

In this example, the code attempts to call non-functions as funwing. The following sample generates C2064:

// C2064.cppint i, j;char* p;void func() {j = i();    // C2064, i is not a functionp();        // C2064, p doesn't point to a function}

You must call pointers to non-static member functions from the context of an object instance. The following sample generates C2064, and shows how to fix it:

// C2064b.cppstruct C {void func1() {}void func2() {}};typedef void (C::*pFunc)();int main() {C c;pFunc funcArray[2] = { &C::func1, &C::func2 };(funcArray[0])();    // C2064 (c.*funcArray[0])(); // OK - function called in instance context}

Within a class, member function pointers must also indicate the calling object context. The following sample generates C2064 and shows how to fix it:

// C2064d.cpp// Compile by using: cl /c /W4 C2064d.cppstruct C {typedef void (C::*pFunc)();pFunc funcArray[2];void func1() {}void func2() {}C() {funcArray[0] = &C::func1;funcArray[1] = &C::func2;}void func3() {(funcArray[0])();   // C2064(this->*funcArray[0])(); // OK - called in this instance context}};

 

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.