Question 7: Predict the output.
class DemoClass
{
public:
DemoClass()
{
m_data = 20;
}
operator int()
{
return m_data;
}
private:
int m_data;
};
int main()
{
DemoClass obj;
int value = obj;
std::cout<<"Value : "<<value;
}
Options:
a) Value : 20
b) Compilation Error. error C2440: 'initializing' : cannot convert from 'DemoClass' to 'int'
c) Run time crash.
d) None of the above.
Answer: a
No comments:
Post a Comment