提问人:George kirby 提问时间:9/11/2023 最后编辑:JoelGeorge kirby 更新时间:9/11/2023 访问量:118
为什么 MSVC 认为此函数的输入参数是 int 类型,但事实并非如此?
Why does MSVC think that the input parameter to this function is of type int, although it's not?
问:
我试图了解隐式指针及其用法,但我似乎无法理解为什么我的编译器 (MSVC) 一直谈论为函数的类型,而不是 .this
int
printcmon()
cmon
void printcmon(const cmon* e);
class cmon
{
public:
int x, y;
cmon(int x, int y) {
this->x = x;
this->y = y;
printcmon(this);
}
int getX() const {
const cmon* e = this;
std::cout << e->x << std::endl;
return 0;
}
};
void printcmon(const cmon* e) {
//stuff
}
错误:
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2143: syntax error: missing ',' before '*'
error C2664: 'void printcmon(const int)': cannot convert argument 1 from 'cmon *' to 'const int'
message : There is no context in which this conversion is possible
message : see declaration of 'printcmon'
message : while trying to match the argument list '(cmon *)'
答:
0赞
Minxin Yu - MSFT
9/11/2023
#1
第一行之前没有上课 添加声明:void printcmon(const cmon* e);
class cmon;
void printcmon(const cmon* e);
class cmon
{
public:
int x, y;
cmon(int x, int y) {
this->x = x;
this->y = y;
printcmon(this);
}
int getX() const {
const cmon* e = this;
std::cout << e->x << std::endl;
return 0;
}
};
void printcmon(const cmon* e) {
//stuff
}
评论