Sorry for this being a really newbie question; I know that I read it in one of the tutorials but I simply can't find it now...
What I mean is a variable ending with a *, like
Code:int my_var*;
Sorry for this being a really newbie question; I know that I read it in one of the tutorials but I simply can't find it now...
What I mean is a variable ending with a *, like
Code:int my_var*;
A compiler error.
Ones like this though
Are called pointersCode:int *myVar;
Woop?
Maybe it wasn't a variable.. but -something- ends with *...
maybe you saw it written aswhich is pretty much what prog-bman just showed you... and it's evil. don't do it.Code:int* myvar;
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
That's how I always declare pointers.
Looks weird. I guess you could do:Code:int *pointer;
For a compromise...Code:int * pointer;
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared
I can't think of any valid C++ code ends with a *. Maybe a function prototype with a pointer parameter and no variable name specified:>> and it's evil. don't do it.Code:void foo(int* );
major_small must be kidding. Don't take that seriously.
no, I'm not. consider this:Originally Posted by Davedthat makes it look like you may have intended both to be pointers, where only the first one is a pointer... and it just gets messy... for example:Code:int* myVar1,myVar2;usually I declare pointers like so:Code:int* myVar1,myVar2,myVar3,*myVar4,myVar5;as you can see, I generally declare each variable on it's own line.Code:int*myVar1; int myVar2;
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
ohhh, Major Small is using old school declarations, not overloading any one line.
makes for much easier to read declarations.
Originally Posted by Jeff Henager
void junk (vector <Books*>& v);
hmm.. thats like the only time i can see it on the rite side is in a funtion like it was said .
C++ Rules!!!!
------------
Microsoft Visual Studio .NET Enterprise
>> no, I'm not. consider this
I wouldn't consider that to be a question of evil. It's more a question of style. I'd put the evilness on the declaration of multiple variables on one line if something had to be called evil.
Consider this:Same issue, but = 0 is not evil, and there is nothing wrong with int myVar1 = 0;.Code:int myVar1,myVar2,myVar3,myVar4,myVar5 = 0;
My personal style is int* myVar. I never declare multiple pointers on the same line. I rarely declare multiple variables on the same line. This doesn't make the code extraordinarily long, since I rarely declare many variables together (declare variables as locally as possible). I also don't put them on the same line since I always try to initialize variables (especially pointers) when I declare them. The benefit is that it makes clear to me that the type is a pointer to int.
So int* myvar is not evil and IMO you can use it if you like.
I'll agree that it's a question of style, but that style is just evil.
take a look at this page and tell me that it's not evil. Sure, it's just a style, but it's an evil style
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
You're right. Certain styles can be evil.
(But this is not one of them.)
I agree with Daved. Pointers are not a style and they are not evil. They are part of the language, and an important one at that.Originally Posted by Daved
erm, we weren't talking about the pointers themselves, but how you choose to declare them.Originally Posted by MitchellH
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
Hey wait, I said that putting the * next to the type is not evil:I didn't say that pointers themselves aren't evil.Code:int* myvar;
They are.
(Of course, I am only kidding, although I tend to agree with that link in spirit.)
Last edited by Daved; 10-18-2005 at 09:11 PM.