type conversion in C++

#include

using namespace std;

class test
{
private:
int value;

public:
test():value(0) { }
test(int v):value(v) { }
explicit test(const char *ch):value(*ch) { }
operator int() { return value; }
};

int main()
{
test t = 3;
// test t2 = static_cast(“a”); // Compile Time Error!
test t2 = static_cast(“a”);

int val1 = t;
int val2 = t2;

cout << val1 << endl; cout << val2 << endl; } [/code]

Similar Posts:

Comments 2

  1. jayakumar wrote:

    Floating & integral conversion

    Posted 28 Jan 2006 at 9:20 pm
  2. MKSeo wrote:

    Pardon me?

    Posted 29 Jan 2006 at 3:32 pm

Post a Comment

Your email is never published nor shared.