#include当赋值给学号的位数超过十位时会报错,但不影响运行。using namespace std; #include class student { public: int m_Id;//成员变量(属性) string m_name;//成员变量(属性) void showstudent()//成员函数(行为) { cout<<"姓名:"< student p1; p1.m_name="张三"; p1.m_Id=2021535750; p1.showstudent(); } int main() { test01(); return 0; }
#include“overflow in implicit constant conversion”。using namespace std; #include class student { public: int m_Id;//成员变量(属性) string m_name;//成员变量(属性) void showstudent()//成员函数(行为) { cout<<"姓名:"< student p1; p1.m_name="张三"; p1.m_Id=202153575099; p1.showstudent(); } int main() { test01(); return 0; }
这个错误就是:常量转换溢出。C语言中char, int, float, double,unsigned char, unsigned int 等数值有极限范围,当它们之间(隐式)转换时,可能因 数值极限 而超界 溢出。有的编译器会报告这一类型的错误,并不是所有编译器都会报告。
解法2:#includeusing namespace std; #include class stu { public: int m_Id; string m_name; int getid() { return m_Id; } string getname() { return m_name; } }; void test01() { stu p1; p1.m_Id=123; p1.m_name="张三"; cout<<"姓名:"< test01(); return 0; }



