A class is the definition of an user-defined type while an object is an instance of a class.
class foo {}; // definition of a type (implementation omitted for brevity).
struct bar {}; // another definition of a type
foo x; // x is an instance of the foo class, therefore x is an object
bar y; // y is an instance of the bar class, therefore y is an object
Note that in C++, struct and class are exactly the same (they are both classes), the only difference being that members of a class are private by default while members of a struct are public by default. Thus the following definitions are exactly the same:
struct X {
Y(){} // public by default
};
class Y {
public:
X(){} // public by specification
};
As are the following:
struct A {
private:
int m_data; // private by specification
};
class B {
int m_data; // private by default
};
Copyright © 2026 eLLeNow.com All Rights Reserved.