一个异常奇怪的问题,望指点???
我在vc++中首先建了一个工程,并分别编辑了两的文件:1.cpp与2.cpp程序如下:
1.cpp:
#include<iostream.h>
class point
{private:
int x,y;
public:
void setpoint(int a,int b)
{x=a;y=b;}
int getx()
{return x;}
int gety()
{return y;}
};
void afs()
{
point a;
a.setpoint(1,2);
cout<<a.getx()<<endl;
}
2.cpp:
#include<iostream.h>
class point
{private:
int x,y;
public:
void setpoint(int a,int b)
{x=a;y=b;}
int getx()
{return x;}
int gety()
{return y;}
};
void afs()
{
cout<<"asd"<<endl;
}
void main()
{
afs();
point b;
b.setpoint(3,4);
cout<<b.getx()<<endl;
}
在程序运行时两个文件中定义的void afs()不但不会产生冲突,反而main()中的afs();语句执行的是1.cpp文件中的void afs(),不知道这是为什么?望高手指点