views:

137

answers:

4

Is there a name or a term for this type of conversion in the c++ community? Has anyone seen this conversion be referred to as "implicit conversion"?

class ALPHA{};

class BETA{
    public:
        operator ALPHA(){return alpha;}
    private:
        ALPHA alpha;
};

void func(ALPHA alpha){}

int main(){
    BETA beta;
    func(beta);
    return 0;
}
+1  A: 

That is commonly called a conversion operator.

Amardeep
+6  A: 

It's normally called a conversion function. It isn't an implicit conversion per se, but does allow implicit conversion to the target type.

Edit: just checked to be sure -- §12.3.2 of the standard uses the phrase "conversion function".

Edit2: I checked in the official standard, which isn't (at least supposed to be) freely available (though you can buy it from the ISO or most member standards organizations such as ANSI, BSI, etc.) A lot of people prefer to save the money and use the final committee draft, which is free.

Jerry Coffin
where did you check that, can you post the link?
LoudNPossiblyRight
A: 

When calling func(beta) object beta is implicitly converted to type ALPHA. This is only possible because you have implemented operator ALPHA().

Sebastian
+1  A: 

Implicit conversion is often referred to as coercion.

FredOverflow