Is code in a class repeated for each instance?
No, it is not repeated. Unless you are using templates, each method of
each class is stored only once in the compiled program. Or even not
stored at all if the optimizer notices it is not used.

Just to demystify the classes a bit, you can consider them as a kind of
“syntactic sugar” over an “object oriented” programming pattern. The
following C++ code:

class MyClass {
public:
    int aMember;
    long anotherMember;
    int aMethod(short);
};

int MyClass::aMethod(short theParameter)
{
    return aMember + theParameter;
}

void some_function()
{
    MyClass objects[2];
    objects[1].aMethod(42);
}


is interpreted by the compiler as being roughly equivalent to this C
code:

typedef struct {
    int aMember;
    long anotherMember;
} MyClass;

int MyClass_aMethod(MyClass *this, short theParameter)
{
    return this-&gt;aMember + theParameter;
}

void some_function()
{
    MyClass objects[2];
    MyClass_aMethod(&amp;objects[1], 42);
}


Can you spot the differences and the similarities?