Im beginner to programming. I have to learn it for one of my uni courses.
I was reading about structures and they keep talking about "instances". So, I was wondering what is an instance in a structure???
That's one of the codewords that you'll hear in OO programming. Often enough it is useful just to try Wikipedia with such terms.
There is the blueprint, and then there are the actual houses.
A class is the blueprint. An instance is a house. In C++, the word "object" is typically synonymous with an instance, but not always... (It is one of those fuzzy words whose meaning sometimes changes with context.)
class CRectangle
{
int x, y;
public:
void set_values (int,int);
int area (void);
}
//Above is the 'class' (the 'definition' or 'blueprint' of how instances will be)
CRectangle rectangle1;
// rectangle1 is an 'instance' of the class
yea you got it... and i like Duoas your metaphores...ok desichor7..think of this...
you have Birds as an example...
1 2 3 4 5 6 7 8 9 10 11
class Bird
{
public:
string BirdName;
};
//That is your class...and an instnace of a class would be a 'type' of bird...
Bird robin; //a robin is a type of bird so it belongs in the 'Bird' class.
// and 'robin' is an instance of that class...
robin.BirdName = "Robin"; //this is just showing properties...
or even this...this is how i grasped classes haha...
class Cat
{
public:
int Cat_Age;
string Cat_Name;
void Cat_Talk();
};
void Cat::Cat_Talk()
{
cout << Cat::Cat_Name << " said Meow!";
}
/* ok...we have a class...Cat and then to create an instnace of that class..you do this...
*/
Cat bashful;
//That is creating an instance called 'bashful' of that Cat class...then
//you can edit it's properties...
bashful.Cat_Name = "Bashful";
bashful.Cat_Age = "2";