You need to step back a bit; let's look at C.
In C, you can write code like this.
1 2 3 4 5 6 7 8 9 10
|
int main()
{
int a, b, c_sq;
a = 3;
b = 4;
c_sq = a*a + b*b;
return 0;
}
|
Now, what if we wanted to create our own 1024bit integer type and use it similarly? Well in C, define a struct to hold your data structure, and you'd create a set of functions that look like:
1 2 3 4 5 6
|
void int1024_init(struct int1024**);
void int1024_release(struct int1024*);
void int1024_set_from_string(struct int1024*, const char*);
void int1024_set_from_double(struct int1024*, double);
void int1024_add(struct int1024* ret, struct int1024* a, struct int1024* b);
void int1024_mul(struct int1024* ret, struct int1024* a, struct int1024* b);
|
Then to use it, your code miight look like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
int main()
{
struct int1024 *a, *b, *c_sq;
int1024_init(&a);
int1024_init(&b);
int1024_init(&c_sq);
int1024_set_from_string(a, "3");
int1024_set_from_string(b, "4");
{
struct int1024 *a_sq, b_sq;
int1024_init(&a_sq);
int1024_init(&b_sq);
int1024_mul(a_sq, a, a);
int1024_mul(b_sq, b, b);
int1024_add(c_sq, a_sq, b_sq);
int1024_release(b_sq);
int1024_release(a_sq);
}
int1024_release(c_sq);
int1024_release(b);
int1024_release(a);
return 0;
}
|
C++ allows you to create user defined types that act like built in types. So you can create a new class of object, int1024. The C++ language guarantees known behaviour when these things are created, destroyed, copied and moved using constructors, destructor and assignment operators.
You can also define your own + and - operators. This is called operator overloading. There's a whole bunch of operators that can be overloaded.
Putting it al together, the C++ equvalent of that C program would be:
1 2 3 4 5 6 7 8 9 10
|
int main()
{
int1024 a, b, c_sq;
a = 3;
b = 4;
c_sq = a*a + b*b;
return 0;
}
|
There's some detail here:
http://en.cppreference.com/w/cpp/language/operators