How do I overload

I have the code written but now I have to overload the void drawBar() I am lost on how to do this any help would be appreciated.

#include "stdafx.h"
#include <iostream>
using namespace std;

void printTriangle(int);
void drawBar(int);






void printTriangle(int bs){
for(int i = 0; i <= bs; i++){
drawBar(bs);
cout << endl;
}
}

void drawBar(int barSize)
{

while (barSize != 0)
{
barSize--;
cout << '*';
}
cout << endl;
}

int main() {
int triangleBase = 0;
char answer;

cout << "This program draws a Triangle" << endl;
do {
cout << "How big of a base would you like?\n";
cin >> triangleBase;


for (int i = 1 ; i <= triangleBase ; i++)
{
drawBar(i);
}
cout<<"\nProcess Another? Y/N ";
cin>>answer;
}while (answer=='y' || answer=='Y');

return 0;
}
I have how to do it but these really don't help me because they are set up differently. I am learning the voids and things and they have me all confused. The setups in all the examples I can find show them without voids and look easier.
hmm well, the basics of function overloading is when you define two functions that take different arguments, but they have the same name. Your current drawBar() function takes an integer as its argument. To overload it to take a char or something is pretty simple you just write out another function which is named drawBar that has char as its argument instead of int.

void drawBar(int bs); //<-- your function
void drawBar(char c); // <-- overloaded function

I don't know why you would want drawBar to take a character.. I guess you could overload it to take a float but that's a little pointless because floats and integers are type castable.

If you want to overload it so you can call it without any arguments then you just write out void drawBar() without any arguments.

Hope I've helped!

.. and to be fair this could all pretty much be gleaned from the article Duoas posted.
Topic archived. No new replies allowed.