1

This is more of a syntactical question than anything else. Imagine I have some struct called "Integer", which contains a boolean called "is_active" and an int called "value". Does there exist some OOP trickery that would allow me to do something as follows:

struct Integer
{
    int value, bool is_active;
    void operator = (int n)
    {
        value = n;
    }
    //insert trickery here
}

int main()
{
    Integer a = 3;
    int b = a;  //This is what I'm after. This line should set b equal to a.value.
}

Any help would be greatly appreciated.

  • 1
    Note that `Integer a = 3;` is *initialization* (construction) and not assignment. And what you seem to be looking for is *conversion operators*. All of this should be covered in any [decent C++ book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list/388282#388282). – Some programmer dude Nov 19 '21 at 10:16

0 Answers0