Subscribe For Free Updates!

We'll not spam mate! We promise.

Apr 14, 2013

How do I use class and struct?




How do I use class and struct?

A C++ struct (or class) is almost like a struct in C (i.e. a set of attributes), but
has two additional kinds of members: methods and data types. A class' method has
to be used with an instance of that class. The important is that methods have always
access to their instance's attributes and data types.

struct A
{
typedef char t_byte; // type
unsigned char i; // attribute
void m() // method
{
t_byte b = 1; // m can access type t_byte
3
i = b; // m can access attribute i
}
};
void function()
{
A a;
a.m(); // an instance is required to call a method.

TechniqZone Socializer Widget
SOCIALIZE IT →
FOLLOW US →
SHARE IT →

0 comments:

Post a Comment