Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

FRIENDS, STATIC, GLOBALS

Name: Anonymous 2010-11-09 13:59

these 3 things i've been told to never use, Globals I can kinda understand, but static and friends...? wtf

Name: Anonymous 2010-11-09 14:00

note the static is the static keyword

Name: Anonymous 2010-11-09 14:03

Who has been spreading these vicious lies?

Name: Anonymous 2010-11-09 14:04

Do not use advices form people who have no idea what they're talking about.

Name: Anonymous 2010-11-09 14:07

>>4
my comp sci professor....

Name: Anonymous 2010-11-09 14:09

Friends are stupid. Globals and staticness are not.

Name: Anonymous 2010-11-09 14:13

>>6
how are friends stupid?

need to rewrite some code? wait no just friend it

Name: Anonymous 2010-11-09 14:18

>>6
ronry fag detected

Name: Anonymous 2010-11-09 14:24

will the variable always be passed by reference?
if yes, make it global

else
no

do different instantiations rely on something between them?
if yes make that thing static

are you going to reuse a lot of code that you already made and don't feel like copy pasta...?
Make it a friend and include

Name: Anonymous 2010-11-09 15:14

friends = one more reason to use mixins (or roles)

Name: Anonymous 2010-11-09 19:13

CAN SOMEONE TELL ME WHAT'S SO WRONG ABOUT HAVING FRIENDS!!! errr using friends?

Name: Anonymous 2010-11-09 19:18

less of this

Name: Anonymous 2010-11-09 20:53

stick to simple c++ please or better still, just use c

Name: Anonymous 2010-11-09 22:16

more of this

Name: Anonymous 2010-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: Anonymous 2010-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: Anonymous 2010-11-10 15:10

>>16
>>15
now do friends

Name: Anonymous 2010-11-10 15:20

>>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.

Name: Anonymous 2010-11-10 15:23

>>18
You're professor

Name: Anonymous 2010-11-10 16:47

>>19
No, I am the professor.

Name: Anonymous 2010-11-10 18:18

So what's the stats of GOTO these days?

Name: Anonymous 2010-11-10 19:46

>>21
stats
IHBT

Name: Anonymous 2010-11-10 20:31

>>21
never use makes program readability horrible

professor 2nd day of class upon asking

Name: Anonymous 2010-11-10 20:47

>>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;
};
 
void CRectangle::convert (CSquare a) {
  width = a.side;
  height = a.side;
}
 
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"

Name: Anonymous 2010-11-10 20:48

Name: Anonymous 2010-11-10 21:07

>>24
I see... now why would people bitch about friends?

Name: Anonymous 2010-11-10 21:15

>>23
This is why no one takes community colleges seriously.

Name: Anonymous 2010-11-10 21:23

>>27
....state college actually

Name: Anonymous 2010-11-10 21:57

>>24
That's sort of like a protected class in Java - "public for classfiles in this directory only."

Name: Anonymous 2010-11-11 15:44

Friends, Romans, countrymen, lend me your ears.

Name: Anonymous 2010-11-11 16:27

>>30
Yea verily, Anthony. As yet when will ye returns't them ?

Don't change these.
Name: Email:
Entire Thread Thread List