![]() ![]() That is, every Square that we create will reference the exact same instance of ShapeType representing squares. ![]() The basic idea is that for each type of shape (Square, Pentagon, Hexagon, etc.), there will be exactly one instance of the ShapeType struct. You'll also note this funky "size" thing, which we use to allow a Shape to be allocated with additional space for a buffer, which we will use to store the data for a shape subclass. This type information is how we perform dynamic dispatch (i.e. In the above code, note that we created an extra object representing the type of the shape. Let's consider a simple class that cannot be overriden (has no virtual methods): // Header class Point įor the Shape base class, we might declare the following C code: // shape.h struct Shape struct ShapeType ShapeType* ShapeType_create ( However, did you know that you don't need to use an OOP language in order to use OOP style and get some of the benefits of object-oriented programming? In this tutorial, I will explain how we can bring some of the style of object-oriented programming to C, a language without built-in OOP support. Programming languages like C++ and Java have built-in support for OOP concepts. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |