I am fairly new to object oriented programming, but have two simple questions on a piece of code. Note that this code has been simplified greatly without changing the net result:
#include <stdio.h>
#include <iostream.h>
class first_one
{
int x;
int y;
public: first_one()
{
x = 1;
y = 2;
}
};
class second_one
{
int z;
public: second_one()
{
z = 3;
}
void print_it()
{
printf("%d %d %d %d %d %d %d");
}
};
void main()
{
first_one A;
second_one B;
B.print_it();
}
The following is printed:
-403 592 -221 3 2 1
Why does this occur?
Also, what C++ or object oriented principle did I violate?