CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2005
    Posts
    1,030

    Help with a compiler error

    Here is the code,
    Code:
    class A
    {
    public:
    	A(int* p)
    	{
    		ptr(p);
    	}
    
    private:
    	int* ptr;
    };
    There is a compiler error "error C2064: term does not evaluate to a function taking 1 arguments" from the statement ptr(p) . I wander why?

  2. #2
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: Help with a compiler error

    Code:
    A(int* p)
      :ptr(p){
    }

  3. #3
    Join Date
    Aug 2007
    Posts
    858

    Re: Help with a compiler error

    Quote Originally Posted by LarryChen View Post
    Here is the code,
    Code:
    class A
    {
    public:
    	A(int* p)
    	{
    		ptr(p);
    	}
    
    private:
    	int* ptr;
    };
    There is a compiler error "error C2064: term does not evaluate to a function taking 1 arguments" from the statement ptr(p) . I wander why?
    ptr(p) is either a function call, or the creation of a temporary object of type ptr which has a ctor taking an int*. The compiler can't find a match for either. If you intended to use an initialization list, look at ZuK's post. Otherwise you need to do ptr = p.

  4. #4
    Join Date
    Jul 2005
    Posts
    1,030

    Re: Help with a compiler error

    According to the same reasoning, we can't put the statement ptr(p) in a initialization list either. Then why can we put the same statement in initialization list? Thanks.
    Quote Originally Posted by Speedo View Post
    ptr(p) is either a function call, or the creation of a temporary object of type ptr which has a ctor taking an int*. The compiler can't find a match for either. If you intended to use an initialization list, look at ZuK's post. Otherwise you need to do ptr = p.

  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Help with a compiler error

    Quote Originally Posted by LarryChen View Post
    According to the same reasoning, we can't put the statement ptr(p) in a initialization list either.
    A computer language has syntax, and a lot of the rules of the syntax deals with context.

    In the context of a function block, that ptr(p) means one thing, in the context of an initialization list, it means another. If the rules of C++ are expanded in the future, maybe ptr(p) means something else within that new context. You can't use "reasoning" here -- those are the rules of the language.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured