-
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?
-
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 ;)
-
Congratulations x 2!
#1 for solving the problem
#2 for working out what I was trying to say!
Thanks muchly!
-
Tip: use code tags. Then you don't need long lines of undescores to keep your code indented.
-
... Not entirely sure how code tags work. Care to elaborate?
-
[ code]
Your code here
[/ code]
Remove the spaces.
Then your code will preserve formatting:
Code:
int main()
{
// indentation
printf("Hello, World!");
return 0;
}