CalmaKarma
CalmaKarma

Reputation: 61

What are aliases like after compilation in C++?

Are aliases regarded as adentical to its original after compilation? In other words, is alias a sugar syntax that only remains during coding?

Upvotes: 0

Views: 87

Answers (1)

Mateo
Mateo

Reputation: 141

The documentation says:

A type alias declaration introduces a name which can be used as a synonym for the type denoted by type-id. It does not introduce a new type and it cannot change the meaning of an existing type name. There is no difference between a type alias declaration and typedef declaration.

If you see some code like this in Godbolt:

struct VeryLongNamedType {
    int n;

    VeryLongNamedType(int n){
        this->n = n;
    }
};

int main(){
    using Type = VeryLongNamedType;

    Type a(8);
    VeryLongNamedType b(9);
}

You'll notice that the using statement doesn't produce any instruction. Even when constructing, both lines call the same constructor.

Short answer: It's just syntactic sugar.

Upvotes: 3

Related Questions