出现函数重载错误call of overloaded ‘printfSth(double)’ is ambiguous

class C:
{
	public:
		void printfSth(int i)
		{

			cout<<"C::printfSth(int i):"<<i<<endl;

		}
		void printfSth(float i)
		{
			cout<<"C::printfSth(float i):"<<i<<endl;

		
		}



};

int main()
{

	A* a = new A();
	a->printfSth();
	C* c=new C();
	c->printfSth(1.1);

}

 原因在与c++,默认将小数认为是double类型,在上面程序调用时,double类型需要做类型转换

但是转成float还是inti,编译器不知道。

原文链接: https://www.cnblogs.com/hong2016/p/6783160.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    出现函数重载错误call of overloaded ‘printfSth(double)’ is ambiguous

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/253240

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月14日 上午6:43
下一篇 2023年2月14日 上午6:45

相关推荐