samedi 22 avril 2023

Static typing concept in C++ [duplicate]

I am going through C++ primer (fifth edition). In that on page 46 'Key Concept: Static Typing' section it says and I quote

As we’ve seen, the type of an object constrains the operations that the object can perform. In C++, the compiler checks whether the operations we write are supported by the types we use. If we try to do things that the type does not support, the compiler generates an error message and does not produce an executable file.

Do the authors mean that static typing (done by type checking) checks whether a type actually supports an operation, for example, if we have have defined a type 'Calc' with an Add() method, does the compiler actually verifies that Add() is defined as part of static typing?

Or do they mean that if the user of the type is calling Multiply() but if the doesn't have that then compiler checks it as part of static typing?

Which of these two are they referring to in this context?

I googled 'static typing C++ primer' and stackoverflow results didn't seem to have any related questions on this.

Aucun commentaire:

Enregistrer un commentaire