c++11 - why cant i initialize 3 default parameters at a time in c++ -


class complex  { private:  float rp, ip; //const int a=10; //static int b; //static const int c = 50; public: complex(); //complex(float ); /*complex(float,float);*/ complex(float , float = 20, float = 30); }  

the above code works fine when try have 3 default parameters

class complex { private: float rp, ip; //const int a=10;//static int b;//static const int c = 50; public: complex(); //complex(float ); /*complex(float,float);*/ complex(float =10  , float = 20, float = 30); }  

i below error -

main.cpp(12): error c2668: 'complex::complex' : ambiguous call to
overloaded function complex.h(15): 'complex::complex(float,float,float)' complex.h(12): or 'complex::complex(void)'

this fails because compiler cannot know of 2 different functions mean when write

complex c; 

does call

complex(); 

or

complex(float,float,float); 

with 3 default values?

you can around removing complex() constructor , have default construction handled complex(float,float,float) constructor 3 default values.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -