LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-29-2007, 02:51 AM   #1
Jack_chen
LQ Newbie
 
Registered: Jul 2007
Posts: 9

Rep: Reputation: 0
C++ overloading question


use overloading with 2 variable which can:
1. when both variable are numbers, add them up and cout
2. when one is variable and other is char, cout number and char
3. wen both variable are chars, cout
Please help me~ thx...
 
Old 07-29-2007, 02:53 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Do you know what overloading is? If so, this is a very simple task.
 
Old 07-29-2007, 12:33 PM   #3
Jack_chen
LQ Newbie
 
Registered: Jul 2007
Posts: 9

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Nylex
Do you know what overloading is? If so, this is a very simple task.
I know overloading is..
but...if 2 variables are typed in by user, how do I declare that two variables before cin?
 
Old 07-29-2007, 12:37 PM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You'll have to decide what you want the user to input (e.g. two ints, a char and an int, etc).
 
Old 07-29-2007, 01:31 PM   #5
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi, Jack_Chen -

This looks like a homework assignment. We'd be happy to help ... but you've got to take the first step.

Please write some code and post it. It doesn't have to be "correct" - just make an intelligent guess. Nylex is right - the answer is really, really simple.

But you need to post some code before we can help you any further.

OK?

PS:
Please be sure to use "code tags".
 
Old 07-29-2007, 07:44 PM   #6
Jack_chen
LQ Newbie
 
Registered: Jul 2007
Posts: 9

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by paulsm4
Hi, Jack_Chen -

This looks like a homework assignment. We'd be happy to help ... but you've got to take the first step.

Please write some code and post it. It doesn't have to be "correct" - just make an intelligent guess. Nylex is right - the answer is really, really simple.

But you need to post some code before we can help you any further.

OK?

PS:
Please be sure to use "code tags".
ha. I was overthinking...
The question just asked as I posted first time..
And I thought that require user to typein two variable.
But I am curiously want to know how to do so if user can typein any inputs..
Here's my code:

#include <iostream>
using namespace std;

void func(int x, int y) {
cout << " x + y = " << x+y;
}
void func(int x, char y) {
cout << "x = " << x << "\ty = " << y;
}
void func(char x, char y) {
cout << "x = " << x << "\ty = " << y;
}

int main() {
string x, y;//I don't know how to declare on here.
cout << "enter first var: ";
cin >> x;
cout << "and second: ";
cin >> y;
func(x, y);

system("PAUSE");
return 0;
}


Error Code:
no matching function for call to func(std::string&,std::string&)

I'm learning C++ this summer by myself and have hole punches of qestions, is anyone want to add my msn to discuss it?
here is my MSN jack90830@hotmail.com

thx everyone^^

Last edited by Jack_chen; 07-29-2007 at 07:55 PM.
 
Old 07-29-2007, 11:39 PM   #7
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
As I said, you'll have to decide what you want the user to input. Can't you ask them to enter an int and a char, or two chars??
 
Old 07-30-2007, 12:42 AM   #8
Jack_chen
LQ Newbie
 
Registered: Jul 2007
Posts: 9

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Nylex
As I said, you'll have to decide what you want the user to input. Can't you ask them to enter an int and a char, or two chars??
en.... thx a lot
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Overloading ioctl() barunparichha Linux - Software 1 06-28-2006 12:38 PM
java...operator overloading question arunvk Programming 6 03-23-2006 07:31 AM
overloading a template allomeen Programming 1 01-26-2006 06:59 PM
c++ [] operator overloading exodist Programming 12 04-17-2004 03:06 PM
<< overloading lazyboy0001 Programming 2 04-10-2004 07:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration