-
July 18th, 2010, 02:53 PM
#1
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?
-
July 18th, 2010, 03:02 PM
#2
Re: Help with a compiler error
Code:
A(int* p)
:ptr(p){
}
-
July 18th, 2010, 03:06 PM
#3
Re: Help with a compiler error
Originally Posted by LarryChen
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.
-
July 18th, 2010, 03:29 PM
#4
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.
Originally Posted by Speedo
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.
-
July 18th, 2010, 03:39 PM
#5
Re: Help with a compiler error
Originally Posted by LarryChen
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|