|
-
March 25th, 2009, 05:16 PM
#1
destructor. friend, and copy constructor
I am working on a program and need to make a friend, deconstructor, and copy constructor.....
I was given this formula for the destructor and completely confused...
cout << value1 << value2
I also do not seem to see a whole lot of information on copy constructors and friends so was wanting to know if someone can help me in exactly what I have to do for these.....
Code:
#include<iostream>
#include<string>
using namespace std;
class Arithmetic
{
public:
int Add(int num1, int num2);
int Subtract(int num1, int num2);
int Multiply(int num1, int num2);
private:
int addedTotal, subtractedTotal, multipliedTotal;
};
//Adding the two numbers together
int Add(int num1, int num2)
{
int addedTotal;
addedTotal = num1 + num2;
cout << endl << "The two numbers added together are: " << addedTotal;
return addedTotal;
}
//Subtracting the two numbers together
int Subtract(int num1, int num2)
{
int subtractedTotal;
subtractedTotal = num1 - num2;
cout << endl << endl << "Subtracting the first and second number give a difference of: " << subtractedTotal << endl ;
return subtractedTotal;
}
//Multiplying the two numbers together
int Multiply(int num1, int num2)
{
int multipliedTotal;
multipliedTotal = num1 * num2;
cout << endl << "Numbers 1 and 2 multiplied together give a product of: " << multipliedTotal << endl << endl;
return multipliedTotal;
}
int main()
{
int num1, num2;
cout << "Enter the first number: ";
cin >> num1;
cout << endl << "Enter the second number: ";
cin >> num2;
Add(num1, num2);
Subtract(num1, num2);
Multiply(num1, num2);
}
-
March 25th, 2009, 05:27 PM
#2
Re: destructor. friend, and copy constructor
Code:
cout << value1 << value2
This has nothing to do with a destructor.
-
March 26th, 2009, 12:45 AM
#3
Re: destructor. friend, and copy constructor
I am not getting your code.... what are you trying to do here....
You have declared the function in a class definition but defined it globally without class reference...
Also there is no class object created in main() to access these functions.... !!!
-
March 26th, 2009, 01:32 AM
#4
Re: destructor. friend, and copy constructor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|