function overloading

tried this tutorial and won't run

Page 1 of 1

6 Replies - 772 Views - Last Post: 08 November 2008 - 12:28 PM Rate Topic: -----

#1 shawncox   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 26-October 08

function overloading

Post icon  Posted 08 November 2008 - 11:01 AM

I'm hung up still, with fuction overloads.
Now I copied this tutorial and I can not get this to run.

#include <conio.h>
#include <iostream>
class arith
{
public:
void calc(int num1)
{
cout << "\n\nSquare of number is :" << num1 * num1 << endl;
}
void calc(int num1,int num2)
{
cout << "\n\n Multiplication of number is :" << num1 * num2 <<endl;
}
};


void main()
{
clrscr();
arith a;
a.calc(5);
a.calc(2,4);
getchr();

}

Is This A Good Question/Topic? 0
  • +

Replies To: function overloading

#2 GWatt   User is offline

  • member icon

Reputation: 307
  • View blog
  • Posts: 3,105
  • Joined: 01-December 05

Re: function overloading

Posted 08 November 2008 - 11:03 AM

what doesn't work exactly?
Was This Post Helpful? 0
  • +
  • -

#3 shawncox   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 26-October 08

Re: function overloading

Posted 08 November 2008 - 11:39 AM

this is what I get:

9 class_arith_overload.cpp `cout' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
class_arith_overload.cpp `endl' undeclared (first use this function)
class_arith_overload.cpp In member function `void arith::calc(int, int)':

13 class_arith_overload.cpp `cout' undeclared (first use this function)
13 class_arith_overload.cpp `endl' undeclared (first use this function)
13 class_arith_overload.cpp At global scope:
19 class_arith_overload.cpp `main' must return `int'
class_arith_overload.cpp In function `int main(...)':
20 class_arith_overload.cpp `clrscr' undeclared (first use this function)
Was This Post Helpful? 0
  • +
  • -

#4 GWatt   User is offline

  • member icon

Reputation: 307
  • View blog
  • Posts: 3,105
  • Joined: 01-December 05

Re: function overloading

Posted 08 November 2008 - 11:41 AM

You have to put using namespace std; after your include statements
Was This Post Helpful? 0
  • +
  • -

#5 shawncox   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 26-October 08

Re: function overloading

Posted 08 November 2008 - 12:04 PM

View PostGWatt, on 8 Nov, 2008 - 10:41 AM, said:

You have to put using namespace std; after your include statements



THX
Very much appreciated!!!
Was This Post Helpful? 0
  • +
  • -

#6 shawncox   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 26-October 08

Re: function overloading

Posted 08 November 2008 - 12:16 PM

//Still didn't work untill I fixed main

#include <conio.h>
#include <iostream>

using namespace std;

class arith
{
public:
void calc(int num1)
{
cout << "\n\nSquare of number is :" << num1 * num1 << endl;
}
void calc(int num1,int num2)
{
cout << "\n\n Multiplication of number is :" << num1 * num2 <<endl;
}
};


int main(int argc, char *argv[])
{
void calc(int num1);
arith a;
a.calc(5);
a.calc(2,4);

system("PAUSE");

return EXIT_SUCCESS;

}
Was This Post Helpful? 0
  • +
  • -

#7 GWatt   User is offline

  • member icon

Reputation: 307
  • View blog
  • Posts: 3,105
  • Joined: 01-December 05

Re: function overloading

Posted 08 November 2008 - 12:28 PM

yeah, declaring main as a void is heavily frowned upon (at least in C)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1