stick to simple c++ please or better still, just use c
Name:
Anonymous2010-11-09 22:16
more of this
Name:
Anonymous2010-11-09 23:31
ok, i'll try to make it simple for op
class Dice{
private:
int face;
public:
Dice(){srand(time(0));rolar();};
static int FACES=6;
int obtainFace();
void roll();
};
int Dice:obtainFace(){return face;}
void Dice::roll(){face=rand()%FACES + 1;}
Every time you create a new Dice you create a new int "face", but you don't create a new int FACES, that's because it's static, it belongs to the class and not to the instance.
Name:
Anonymous2010-11-09 23:31
ok, i'll try to make it simple for op
class Dice{
private:
int face;
public:
Dice(){srand(time(0));rolar();};
static int FACES=6;
int obtainFace();
void roll();
};
int Dice:obtainFace(){return face;}
void Dice::roll(){face=rand()%FACES + 1;}
Every time you create a new Dice you create a new int "face", but you don't create a new int FACES, that's because it's static, it belongs to the class and not to the instance.
>>1
You're professor is telling these lies to you to prevent you newfags fucking up everything right from the start. Until you've learned why those constructions are harmful and what are the exceptions to the rule, obey your professor. Once you've figured shit out, the rule does not apply to you anymore.
>>17
sorry, i forgot. but basically, "friend" allows functions outside the class access it's privates and protected stuff, that's why people bitch about it: example
class CSquare;
class CRectangle {
int width, height;
public:
int area (void)
{return (width * height);}
void convert (CSquare a);
};
class CSquare {
private:
int side;
public:
void set_side (int a)
{side=a;}
friend class CRectangle;
};
int main () {
CSquare sqr;
CRectangle rect;
sqr.set_side(4);
rect.convert(sqr);
cout << rect.area();
return 0;
}
here, CRectangle can access the "private int side" from CSquare because CRectangle was declared friend of CSquare.
That's the basic notion of "class friendship"