error C2600: 'Point::Point' : cannot define a compiler-generated special member function (must be de

来源:互联网 发布:seo h1标签 编辑:程序博客网 时间:2024/05/18 15:04

1、运行程序时,出现这个error C2600: 'Point::Point' : cannot define a compiler-generated special member function (must be declared in the class first)错误,感觉没什么问题,仔细一看才发现,是我错了。

2、我以为,不带参数的构造函数可以不用声明就直接在类外定义,没想到也需要在类外定义。

错误代码如下:

2_2_1.h#ifndef _2_2_1_H_#define _2_2_1_H_class Point{private:int x;int y;public:void output();};#endif2_2_1.cpp#include"iostream.h"#include"2_2_1.h"void Point::output(){cout<<"x:"<<x<<"  y:"<<y<<endl;}void Point::Initial(){x = 5 ;y = 7 ;}Point::Point(){x = 6;y = 6;}void main(){Point pt;pt.output();//构造函数的效果和Initial函数的效果是一样的pt.Initial();//类似于自己买零件,再用自己买的零件组装电脑。pt.output();//输出5和7}
正确代码如下:
2_2_1.h#ifndef _2_2_1_H_#define _2_2_1_H_class Point{private:int x;int y;public:void output();Point();<span style="white-space:pre"></span>//错误代码就少了这一句};#endif2_2_1.cpp#include"iostream.h"#include"2_2_1.h"void Point::output(){cout<<"x:"<<x<<"  y:"<<y<<endl;}void Point::Initial(){x = 5 ;y = 7 ;}Point::Point(){x = 6;y = 6;}void main(){Point pt;pt.output();//构造函数的效果和Initial函数的效果是一样的pt.Initial();//类似于自己买零件,再用自己买的零件组装电脑。pt.output();//输出5和7}

0 0
原创粉丝点击