By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,159 Members | 979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,159 IT Pros & Developers. It's quick & easy.

parameters c++

P: 1
If I wanted a function in a class to take one parameter of either int or string, would I have to make to different functions or is there a way to declare it so the program will accept either type in one function. I tried using
void fun(string s=" ", int=-1) but this get an error if I call fun(int i); Any help would be appreciated
Mar 11 '07 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 1,510
If I wanted a function in a class to take one parameter of either int or string, would I have to make to different functions or is there a way to declare it so the program will accept either type in one function. I tried using
void fun(string s=" ", int=-1) but this get an error if I call fun(int i); Any help would be appreciated
in C++ you can have two functions of the same name but with different parameters, see overloaded functions in
http://www.cplusplus.com/doc/tutorial/functions2.html
Mar 11 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.