How is this C++ implicit conversion occurring?

3482 views c++
8

Apologies in advance for this question. It's been awhile since I've used C++ and I can't seem to find an exact tutorial that answers my question. I think this is an example of implicit conversion, but I'm not sure.

Code:

class Square
{
public:        
    Square(int size) : size{size}
    {
    }

    int getSize() const
    {
        return size;   
    }

private:
    int size;
};

void doSomething(Square square)
{
    cout << "doSomething called with " << square.getSize() << endl;   
}

int main()
{
    // Should be passing in a Square type here, but instead passing an int.
    doSomething(23);
    return 0;
}

Output:

doSomething called with 23

Questions:

  1. Is this an example of implicit conversion?
  2. How is this occurring? I'd be satisfied with a link that explains this in more detail. For what it's worth, I've already gone over the cplusplus.com explanation of Type conversions.

Thank you!

answered question

1 Answer

0

This is an implicit conversion Please check here . It has very detailed explanation:

posted this

Have an answer?

JD

Please login first before posting an answer.