|
-
Nov 26th, 2002, 04:51 PM
#1
Thread Starter
Member
An object's data type
Don't know if what I'm about to say will make sense, so bear with me and ask if you don't understand...
When you have a class, in this case an 'Multiplier' class, how can you using the object identifier to return a value?
Example:
{
____Mulitiplier Multi;
____Multi.Number1=2;
____Multi.Number2=4;
____cout << Multi; *
}
This would return 8. I realise it's a useless class, but I'm more concerned about the * line. How could I make this line print the value '8' without having to use a line akin to "cout << Multi.result;"?
Does it have anything to do with class operators?
-
Nov 26th, 2002, 05:31 PM
#2
Junior Member
yes, it has something to do with an operator - in this case it's maybe the int-op.
Code:
class Multi
{
public:
operator int() {return No1 * No2;}
int No1, No2;
};
Multi oMulti;
oMulti.No1 = 2;
oMulti.No2 = 4;
cout << oMulti; // 8
Mikey
-
Nov 26th, 2002, 05:37 PM
#3
Thread Starter
Member
Congratulations x 2!
#1 for solving the problem
#2 for working out what I was trying to say!
Thanks muchly!
-
Nov 26th, 2002, 06:10 PM
#4
Tip: use code tags. Then you don't need long lines of undescores to keep your code indented.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 27th, 2002, 02:09 PM
#5
Thread Starter
Member
... Not entirely sure how code tags work. Care to elaborate?
-
Nov 27th, 2002, 02:21 PM
#6
[ code]
Your code here
[/ code]
Remove the spaces.
Then your code will preserve formatting:
Code:
int main()
{
// indentation
printf("Hello, World!");
return 0;
}
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
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
|