Please place your vote
Printable View
Please place your vote
I didn't think anyone was actually going to do this. Oh well. I can tell you that my least favorite on that list is extern. I think extern should be banned as it is a way of making everything super-global.
Why choose class over sizeof? It's unheard of. I prefer sizeof, it's much easier to type and it sounds better.
while sizeof may be nice, I choose class from my position as an OOP advocate. there was just a thread on finding a type's size without using sizeof (silly beginners :p).
What! That's impossible. Where's this thread?
it's not impossible. I gave the solution...
type *t=0;
t++;
int size = (int)t;
You gave a solution, yes. There are more than one just so everyone knows ;)Quote:
Originally posted by FillYourBrain
it's not impossible. I gave the solution...
type *t=0;
t++;
int size = (int)t;
you're evil
Thats what they tell me.Quote:
Originally posted by FillYourBrain
you're evil
for the record, I meant "I gave the solution" as in "I gave the following solution" not that I am God and I solved the world's problems.
Yeah, and I realize that. I only posted my response because I like to encourage people to find many solutions to problems. I didn't want them to think there was only one way to do it.Quote:
Originally posted by FillYourBrain
for the record, I meant "I gave the solution" as in "I gave the following solution" not that I am God and I solved the world's problems.
Playing around with FYB's idea I came up with an interesting, (albeit ludicrous) application, using it as a sort of data-hiding mechanism.
Code:
class access_level { public:
virtual void access() = 0;
};
class denial : public access_level { public:
int a;
void access(){ MessageBox(NULL, "Get outa here!", "Access Denied!!", MB_OK); }
};
class level_3 : public access_level { public:
int a, b;
void access(){ MessageBox(NULL, "Free to roam the bottom floor.", "Hello employee.", MB_OK); }
};
class level_2 : public access_level { public:
int a, b, c;
void access(){ MessageBox(NULL, "Free to browse.", "Good day, supervisor.", MB_OK); }
};
class level_1 : public access_level { public:
int a, b, c, d;
void access(){ MessageBox(NULL, "You may do as you wish", "Top of the day, Mr. President.", MB_OK); }
};
void * security_level_token(){
void * key_type = NULL;
void * employee = ((level_3*)NULL+1);
void * supervisor = ((level_2*)NULL+1);
void * president = ((level_1*)NULL+1);
/*
Add code to determine what admin
level we're currently running in...
*/
key_type = president; //...change this line...//
return key_type;
}
access_level * access_point(void * unknown){
access_level * privilage = (access_level*)unknown;
int type = (int)privilage;
if(type == sizeof(level_3))
return new level_3;
else if(type == sizeof(level_2))
return new level_2;
else if(type == sizeof(level_1))
return new level_1;
return new denial;
}
int main(){
/* caller knows no details of the implementation */
void * unknown_level = security_level_token();
access_level * my_level = access_point(unknown_level);
my_level->access();
return 0;
}
... this ... thread ... makes ... no ... sense ...
Hehe I was being sarcastic when I wrote this:
http://www.cprogramming.com/cboard/s...832#post195525
I agree and class is not a fav of mine either. I guess the only one i really like in here is "int". HE! HE! HE!Quote:
Originally posted by Eibro
Why choose class over sizeof? It's unheard of. I prefer sizeof, it's much easier to type and it sounds better.
Later,
cj