Can I assign a object to a integer variable?

Posted by AKN on Stack Overflow See other posts from Stack Overflow or by AKN
Published on 2010-06-14T06:35:59Z Indexed on 2010/06/14 6:42 UTC
Read the original article Hit count: 251

Filed under:
|

Let say I have a object. I'm assigning that to an integer.

MyClass obj1 = 100;//Not valid

Let's say, I have a parameterized constructor which accepts an integer.

MyClass(int Num)
{
    // .. do whatever..
}

MyClass obj1 = 100;//Now, its valid

Likewise on any circumstance, does the vice-versa becomes valid?!.

eg) int Number = obj1;//Is it VALID or can be made valid by some tweeks

© Stack Overflow or respective owner

Related posts about c++

Related posts about coding