CodeBlocks编译以下程序报错
class Time
{
public:
Time();
Time(int,int,int);
void show_time();
private:
int hour;
int minute;
int sec;
};
Time::Time()
{
hour=0;
minute=0;
sec=0;
}
Time::Time(int h,int m,int s) {
hour=h;
minute=m;
sec=s;
}
void Time::show_time()
{
cout<<"Time:"<<hour<<":"<<minute<<":"<<sec<<endl;
}
int main()
{
Time t1;
t1.show_time();
Time t2={12,10,30};
t2.show_time();
return 0;
}
错误提示:
||=== Build: Debug in test1-ten (compiler: GNU GCC Compiler) ===|
D:\CJJP\test1\test1-ten\main.cpp||In function 'int main()':|
D:\CJJP\test1\test1-ten\main.cpp|22|error: in C++98 't2' must be initialized by constructor, not by '{...}'|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
解决办法:
选择设置-编译器
![](https://i-blog.csdnimg.cn/blog_migrate/a2719fd113904d14fe63f895ee0325c4.png)
勾选C++11标准
![](https://i-blog.csdnimg.cn/blog_migrate/8cee319068eef96323c59cb8902742b4.png)
确认后编译运行 ,ok了 错误解决