大家看一下,一段VC的小代码,就是通不过。。。我看不出哪里不对~~!!

来源:百度知道 编辑:UC知道 时间:2024/04/29 07:58:59
#include <iostream>
using namespace std;

class point {
private:
int x,y;
public:
void set(int new_x,int new__y);
int get_x();
int get_y();
};

int main(){
point Pt1;
pt1.set(44,55);
cout <<"X,Y are "<< p1.get_x() << p1.get_y();
return 0;
}

void point::set(int new_x,int new_y){
x = new_x;
y = new_y;
}

int point::get_x(){
return x
}

int point::get_y(){
return y;
}

debug :d:\program files\microsoft visual studio\myprojects\小程序\实验.cpp(47) : error C2065: 'pt1' : undeclared identifier
d:\program files\microsoft visual studio\myprojects\小程序\实验.cpp(47) : error C2228: left of '.set' must have class/struct/union type
d:\program files\microsoft visual studio\myprojects\小程序\实验.cpp(48) : error C2065: 'p

#include <iostream>
using namespace std;

class point {
private:
int x,y;
public:
void set(int new_x,int new__y);
int get_x();
int get_y();
};

int main(){
point Pt1;
Pt1.set(44,55);
cout <<"X,Y are "<< Pt1.get_x() << Pt1.get_y();
return 0;
}

void point::set(int new_x,int new_y){
x = new_x;
y = new_y;
}

int point::get_x(){
return x ;
}

int point::get_y(){
return y;
}

改好了,其实就是Pt1有的没大写的问题~还少一个分号,lz粗心喽

出错信息明明白白的告诉你了:
debug :d:\program files\microsoft visual studio\myprojects\小程序\实验.cpp(47) : error C2065: 'pt1' : undeclared identifier

实验.cpp的第47行 pt1:未声明的标识

undeclared identifier:未声明的标识符,你前面声明的是Pt1,但后面确pt1,这两个标识符是完全不一样的,应该注意一下啊!
还有就是return x少了个分号;;;;;;;
顶一楼的,lz真是粗心啊