您的位置:首页 > 编程语言 > C语言/C++

C/C++_两种函数不能重载的情况

2015-07-28 14:58 204 查看
首先介绍构成函数重载的条件:函数的参数类型不同,参数个数不同才能构成函数的重载

情况一: 参数完全相同,只有返回值不同

示例 :

void print();

int print();

由于只有返回值不同故无法区分到底调用那个函数,因此不能重载

情况二:
语意不明确


示例:

KK(int x , int y = 10){

this->x = 10;

this->y = y;

}

KK(int x){

this->x = 10;

this->y = 10;

}



完整程序

#include <cstdio>
#include <iostream>

using namespace std;

typedef class KK{
public:
	KK(int x , int y = 10){
		this->x = 10;
		this->y = y;
	}
	KK(int x){
		this->x = 10;
		this->y = 10;
	}
	~KK(){

	}
	int x;
	int y;
	void print(){
		cout << x << endl << y << endl;
	}
}*LPPoint, Point;

int main(){
	LPPoint pt = (LPPoint)(new Point(3));

	pt->x = 5;
	pt->y = 5;

	pt->print();

	cout << sizeof(Point) << " " << sizeof(int) << endl;
	delete pt;

	return 0;
}


VS2013报错信息

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: