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

94 篇文章 0 订阅
30 篇文章 0 订阅

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();
};

#endif

2_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>//错误代码就少了这一句
};

#endif

2_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
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值