c++ - Can I assign a object to a integer variable? -


Assume that I have an object I am specifying an integer

  MyClass obj1 = 100; // Not valid  

Let me assume that I have a parametric constructor that accepts the integer.

  MyClass (Int Num) {// .. whatever ..} MyClass obj1 = 100; // Now, its valid  

In any case similarly, the sub-reverse becomes valid?!

  for example) int number = obj 1; // Whether it is valid or something can be validated by TEEEX  

EDIT :

I use the conversion functions It is possible to do The conversion function is often called the "cast operator" because they (with the constructor) are saying that when

For example, many people have explained it

Yes, provided the object A int , either directly or through an intermediate object. For example, if your class has a conversion operator int it will work:

  MyClass {public: operator int () const {Return 200}; }};  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -