![]() |
Failure to Distinguish Overloading from Default Initialization
Hi all,
I got a code in the net. I executed that one , it is working fine..I did not understand how it is working.. can anybody explain me? code is.. c12.h Code:
#ifndef C12_HCode:
// Failure to Distinguish Overloading from Default Initialization Regards, sharmila. |
Re: Failure to Distinguish Overloading from Default Initialization
please use the proper bbcode so that code is well formatted.
Also regarding your post what is the thing that made you think like that. I dont think there is anything which should not allow the above code to work. |
Re: Failure to Distinguish Overloading from Default Initialization
Hi Shabbir,
My doubt is if we uncomment void (C1::*pmf1)() = &C1::f1; it showing error?But the samething is working fine for C2..the only difference is f1() is taking default argument.The error it is showing is error C2440: 'initializing' : cannot convert from 'void (__thiscall C1::*)(int)' to 'void (__thiscall C1::*)(void)' Here it is not recognizing default argument..why it is so.. Thanks and regards, sharmila. |
Re: Failure to Distinguish Overloading from Default Initialization
Actually void (C1::*pmf1)() means it can hold the pointer to a function having no parameter but f1 in C1 has an argument. The argument is such that if you dont provide a value it can have a default value.
Its confusing with the constructor where having a default constructor is not needed if you specify the values of each of the parameters in the non -default constructor making it default. |
Re: Failure to Distinguish Overloading from Default Initialization
Hi shabbir,
It will happen in overloading.But for class C1 we did not write any constructor, so it will invoke default one.Here it is able to create C1 object but unable to assign function for function pointer. Regards, sharmila. |
Re: Failure to Distinguish Overloading from Default Initialization
No probably I could not make you clearly understand what I meant.
When we write any constructor having all the parameters default value we call him default constructor but actually the default constructor with no param is different in function signature than having default params of all. I hope now its a bit more clearer |
| All times are GMT +5.5. The time now is 13:42. |