|
ex6-8.cpp - Example 6-8 Type Conversions (1) |
// File: ex6-8.cpp - Conversion of a user-defined type to a primitive type
#include <iostream>
using namespace std;
class A {
int a;
public:
A(int i) : a(i) {}
};
class B {
int b;
public:
B(int i) : b(i) {}
operator int() const;
};
B::operator int() const
{
cout << "* B:: operator int() called\n";
return b;
}
int main()
{
B eight(8);
cout << eight << endl;
cout << eight + 5 << endl;
cout << 5+ eight << endl;
cout << (eight > 3) << endl;
return 0;
}
CIS27: Programming in C++ Instructor: Joe Bentley