比如: XXX.CPP class Teacher { private: int year; } class Student { private: int year; } void main() { Teacher a; //类名不同,对象名同 Student a; //类名不同,对象名同 ... }
可以吗?
[此贴子已经被作者于2005-6-28 23:13:32编辑过]
比如: XXX.CPP class Teacher { private: int year; } class Student { private: int year; } void main() { Teacher a; //类名不同,对象名同 Student a; //类名不同,对象名同 ... }
可以吗?
[此贴子已经被作者于2005-6-28 23:13:32编辑过]
这种问题亲自调试一下不就知道了!编程是编出来的,不是只凭脑袋分析空想出来的! #include<iostream> using namespace std;
class Teacher { private: int year; }; class Student { private: int year; };
int main() { Teacher a; Student a; return 0; } 调试错误: Compiling... mainp.cpp E:\VC_Examples\test1\mainp.cpp(18) : error C2371: 'a' : redefinition; different basic types E:\VC_Examples\test1\mainp.cpp(17) : see declaration of 'a' Error executing cl.exe.
mainp.obj - 1 error(s), 0 warning(s) ---------------------------------------------------------------------- 挑战自己,超越自己,成就自己!