type conversion in C++

Tags:

#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]

Comments

2 responses to “type conversion in C++”

  1. jayakumar Avatar
    jayakumar

    Floating & integral conversion

  2. MKSeo Avatar
    MKSeo

    Pardon me?

Leave a Reply

Your email address will not be published. Required fields are marked *